Hi,
I'm a total Arduino noob and I'm trying to learn some interesting things. I've made some LEDs blink and am fairly confident with the basics of my hardware stuff (read data from pins, send data to pins).
Now I'm trying to hook my Arduino up to Python in order to make a system that can send a Tweet when it's getting dark in my room. I'm using a light sensor for this and am getting the values the way I want them to.
Now in order to send the Tweet it seems I need a Serial connection (so I can tell my computer stuff) and a program that receives the stuff I send to my computer. I'm using pyserial for receiving Arduino's serial data.
In order to try out my serial connection I decided to take out the light sensor and just try sending data from Arduino to Python. I've read that the first time you send Serial data it's common to miss some data due to Arduino resetting or something (correct me if I misunderstood this).
The Tweet I'm trying to send should be something like: "Hey! Its pretty dark in here man!"
When I use Serial.println("Hey! Its pretty dark in here man!"); to write this, my Python script catches a random amount of characters instead of the whole string. Something like:
Hy Its prtty dak in here ma
is not uncommon to show in my terminal.
My Arduino code looks like this:
void setup() {
Serial.begin(9600);
Serial.println("hello python!");
}
void loop() {
Serial.println("Hey! Its pretty dark in here man!");
delay(2000);
}
And my Python code is:
import serial
import time
arduino = serial.Serial("/dev/tty.usbmodemfa131", 9600);
while 1:
status = arduino.readline()
print(status)
time.sleep(2)
del status
Nothing to fancy here and probably all wrong. Can anybody explain in a beginners language what I'm doing wrong? And also, how can I correct it to actually work?