import serial
import time
ser = serial.Serial(
port = '/dev/ttyAMA0',
baudrate = 9600,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 1
)
while True:
msg = "send message"
print (msg)
ser.write('msg')
time.sleep(5)
The problem is the Ardunio is not recieveing the message, either that or the pi is not sending it.
Have gone through all the steps setting up the pi to send via serial by removing console output to serial.
I am using a Ardunio Pro Micro (was suggested on this forum because of its HID compatibility).
Im also asking on the Pi forums about the pi code and setup and they say its fine.
and i assume 8 bits is 01010101 (binary) which is equle to a single character, not 100% sure on how serial works but im sending an entire string across "msg" which would be 24 bits. either that or i missed a memo on how bits work...
I did some test on Serial.print however that was on the USB serial port not the RX/TX serial port, which was referred to as Serial1 if im not mistaken, which i could not test without using a pi.
the only reason i put the else statement there was so i could get an output saying nothing is happening.
If its not there i only ever get a black space.
Edited it as per you suggested however still no change at all, just blank.
And yes i get confused between " and ' as they mean different things in different languages.
Ok some success, I didnt notice last nigh (being about 2-3am) but one of the solderd wires had come loose on the pi TX - ard RX pins and was probably why it wasnt working very well.
So resoldured it today (myself this time) and hurah its working ... ish
so first of all 2 things
"Serial.println(Serial1.read());" just prints a value not a string eg:
109
115
103
just repeting that every time
And Robin2, I did look at the examples. Most of it i did not understand, and quite a lot of it is stuff i dont need.
I came up with the following code hopefully stripping out the stuff i didnt need (this is suppose to be 1 way communication)
but as with before it just came up with a random number:
31
31
31
my python code is set to sleep for 1 second after writing. When the Ardunio recieves the numbers its in sets of 3 followed by a 1 second pause then repetes.
Simple serial test code that will capture an incoming string of bytes on the arduino rx pin and echo them back out the tx pin.
//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send
String readString;
void setup() {
Serial.begin(9600);
Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
readString="";
}
}
zoomkat:
Simple serial test code that will capture an incoming string of bytes on the arduino rx pin and echo them back out the tx pin.
//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send
String readString;
void setup() {
Serial.begin(9600);
Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
readString="";
}
}
Thank you, this worked fine with a little adjustment in setting Serial to Serial1.
I was putting
if (Serilal1.availble) {
while (serial1.availble) {
read
print
}
{
so i now know why it was printing them on separate lines ( as it was printing 1 character at a time as the came in)