Hi,
time ago i bought and Arduino UNO from amazon. One of the interesting thigns of Arduino is that, instead of raspberry, you can easily use analog sensors. Maybe this thing can be usefull beacouse you can use Arduino to retrieve information from analog sensors, connect arduino to our raspberry and send information to it.
This is exactly what we are going to do in this post. Connect Arduino to Raspberry Pi and send message to it.
What we need?
- Arduino
- Raspberry (i used Raspberry Pi 3)
- USB cable
nothing else.
So connect Arduino to Raspberry with USB cable
ok, so we can go on.
in raspberry write this cose:
/////////////////////////////////////////
sudo apt-get update
sudo apt-get install arduino -y
/////////////////////////////////////////
in this way you'll install arduino ide on raspberry
you need to download "Time" library for arduino from here.
Extract le archive and in Arduino IDE go to "Sketch -> Import Library -> Add library" and select the extracted folder.
then in Arduino IDE write this code:
/////////////////////////////////////////
#include "Time.h"
void setup() {
Serial.begin(9600);
setTime(12,0,0,1,1,11);
}
void loop() {
Serial.print("Arduino send a message to raspberry");
Serial.print(hour());
Serial.println();
delay(5000);
}
/////////////////////////////////////////
in this way you are using serial port 9600 to send message
in the Arduino IDE upload this code.
now you need to create your python script that is listen incoming message from serial. Create a new python file with this code:
/////////////////////////////////////////
import serial
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600)
while 1:
if(arduinoSerialData.inWaiting() > 0):
myData = arduinoSerialData.readline()
print myData
/////////////////////////////////////////
and this is the output:
StaY TuNed!
time ago i bought and Arduino UNO from amazon. One of the interesting thigns of Arduino is that, instead of raspberry, you can easily use analog sensors. Maybe this thing can be usefull beacouse you can use Arduino to retrieve information from analog sensors, connect arduino to our raspberry and send information to it.
This is exactly what we are going to do in this post. Connect Arduino to Raspberry Pi and send message to it.
What we need?
- Arduino
- Raspberry (i used Raspberry Pi 3)
- USB cable
nothing else.
So connect Arduino to Raspberry with USB cable
ok, so we can go on.
in raspberry write this cose:
/////////////////////////////////////////
sudo apt-get update
sudo apt-get install arduino -y
/////////////////////////////////////////
in this way you'll install arduino ide on raspberry
you need to download "Time" library for arduino from here.
Extract le archive and in Arduino IDE go to "Sketch -> Import Library -> Add library" and select the extracted folder.
then in Arduino IDE write this code:
/////////////////////////////////////////
#include "Time.h"
void setup() {
Serial.begin(9600);
setTime(12,0,0,1,1,11);
}
void loop() {
Serial.print("Arduino send a message to raspberry");
Serial.print(hour());
Serial.println();
delay(5000);
}
/////////////////////////////////////////
in this way you are using serial port 9600 to send message
in the Arduino IDE upload this code.
now you need to create your python script that is listen incoming message from serial. Create a new python file with this code:
/////////////////////////////////////////
import serial
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600)
while 1:
if(arduinoSerialData.inWaiting() > 0):
myData = arduinoSerialData.readline()
print myData
/////////////////////////////////////////
and this is the output:
StaY TuNed!
Commenti
Posta un commento