How to send data from Raspberry Pi Pico to arduino nano?

I want to send 2 data using NRF24L01 or Uarts, the data I measured from Raspberry Pi Pico to Arduino Nano. How can I do that?

Can anyone help?

A bump 16 minutes after posting the question ?

1 Like

I'm a little fussy, sorry.

A serial link would probably be the easiest

What have you tried ?

I find one example from book. But it did not work well for me. I will measurement datas from MPU6050 by using Pico and then i want to send them Arduino Nano.

import machine
import utime
AnalogIn = machine.ADC(4) # ADC channel 4
Conv = 3.3 / 65535 # Conversion factor
 
uart=machine.UART(id=0,baudrate=9600,bits=8,parity=None,stop=1 )
while True: # Do forever
 V = AnalogIn.read_u16() # Read temp
 V = V * Conv # Convert to Volts
 Temp = 27 - (V - 0.706) / 0.001721 # Convert to temp
 Tempstr = str(Temp) # Convert to string
 uart.write(Tempstr[:5]) # Send to UART
 uart.write(" Degrees C\n")
 utime.sleep(10) # Wait 10 seconds



#include <SoftwareSerial.h>
SoftwareSerial MySerial(2, 3); // RX, TX
String Temp;
char ch;
void setup() 
{
 Serial.begin(9600); // Monitor speed 9600
 MySerial.begin(9600); // Soft serial speed 9600
}
void loop() 
{
 if(MySerial.available() > 0) // Data available?
 {
 ch = MySerial.read();
 Temp.concat(ch);
 if(ch == ā€˜\n’)
 {
 Serial.print("Temperature = ");
 Serial.print(Temp); // Display data
 Temp="";
 }
 }
}

What does that mean ?

What happens when you run the programs ?
Why can't you read the sensor using the Nano alone ?

my goal is to write the code using pico. I will either communicate the pico with nrf or do it with this method.

Let the data I send be 100. I don't get 100. It comes in order 1-0-0.

[image]

 Tempstr = str(Temp) # Convert to string

You are sending a String of 3 characters so you get three separate characters. Once received by the Nano you can convert the 3 characters to an integer using the toInt() function

See toInt() - Arduino Reference

1 Like

i will try and i will text thank you

i tried but the value coming to arduino nano is different.

import machine
import utime
 
uart=machine.UART(id=0,baudrate=9600,bits=10,parity=None,stop=1 )
while True: # Do forever
 Temp = 1 # Convert to temp
 Tempstr = str(Temp) # Convert to string
 uart.write(Tempstr[:1]) # Send to UART
 utime.sleep(1) # Wait 10 seconds





String Temp;
void setup() 
{
 Serial.begin(9600); // Monitor speed 9600
}
void loop() 
{
 if(Serial.available() > 0) // Data available?
 {
   Temp.toInt();
 Temp = Serial.read();

 Serial.print("Temperature = ");
 Serial.println(Temp); // Display data
 
 }
}

image

A couple of observations

   Temp.toInt();
 Temp = Serial.read();
  • You are converting Temp to an integer before you even read its value
  • the idea is to build the String from its individual characters and only then to convert it to an integer
1 Like

Is bits supposed to include start and stop, or is it data.
8-N-1
should probably be
uart=machine.UART(id=0,baudrate=9600,bits=8,parity=None,stop=1

1 Like

i tried it but the result same :confused:

Post the code that you tried

import machine
import utime
 
uart=machine.UART(id=0,baudrate=9600,bits=8,parity=None,stop=1 )
while True: # Do forever
 
 Temp = 99
 
 Tempstr = str(Temp) # Convert to string
 uart.write(Tempstr[:2]) # Send to UART
 
 utime.sleep(1) # Wait 10 seconds










 	#include <SoftwareSerial.h>
SoftwareSerial MySerial(2, 3); // RX, TX
String ch;
void setup() 
{
 Serial.begin(9600); // Monitor speed 9600
 MySerial.begin(9600); // Soft serial speed 9600
}
void loop() 
{
 if(MySerial.available() > 0) // Data available?
 {
 ch = MySerial.read();
 int mubi = ch.toInt();
 
 Serial.println(mubi); // Display data
 
 }
}

Read the whole String into a variable and only once you have done that use the toInt() function to convert it to an int

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.