Saturday, December 10, 2022

Arduino nano connect RP2040 Multiprocessing

I'll be trying to use the dual-core 32-bit Arm® Cortex®-M0+. One core for communication and the other to run timers and servo commands for Pinky's gait management.

 Set up the ANC-RP2040:

  • Using Arduino IDE 2.0.3
  • In the boards manager, install MBED OS Nano boards.
  • From the library manager, install wifinina.
Modifying code from this tutorial based on the pi pico RP2040. Found this one to work better.

Using pico/mulitcore.h, usage can be found in C:\Users\*YOUR USER*\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.4.1\cores\arduino\mbed\targets\TARGET_RASPBERRYPI\TARGET_RP2040\pico-sdk\rp2_common\pico_multicore\include\pico\multicore.h

I was having trouble with the cursor jumping to the left when I started a new line or tabbed. Solution was hidden in the preferences menu.

#include <stdio.h>
#include <mbed.h>
#include "pico/multicore.h"
#include <WiFiNINA.h>

void core1_entry() {
  while(true){
    uint32_t time1 = multicore_fifo_pop_blocking();
    if(time1 % 600 == 0){
      digitalWrite(LED_BUILTIN, LOW);
    }
    else if (time1 % 300 == 0){
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}

void setup() {
  Serial.begin(115200);
  while(!Serial){//Wait for serial to come up
    sleep_ms(100);  
  }
  Serial.println("\r\nHello, multicore_BLINKER!");
  multicore_launch_core1(core1_entry);
}

void loop() {
  uint32_t time = millis();
  if(time % 1000 == 0){
    digitalWrite(LEDR, LOW);
  }
  else if (time % 500 == 0){
    digitalWrite(LEDR, HIGH);
  }
  multicore_fifo_push_blocking(time);
}


No comments:

Post a Comment