antichamber
October 19th, 2016, 08:03 PM
So, I'm running IDLE 3 on ubuntu mate on a raspberry pi and have an arduino uno connected via USB. Here is the code on the arduino:
int temp = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.setTimeout(10);
}
void loop()
{
while (Serial.available() > 0)
{
temp = Serial.parseInt();
if (temp == 0)
{
digitalWrite(13, HIGH);
delay(1000); \
digitalWrite(13, LOW);
delay(500);
}
}
if (temp > 0) {
temp--;
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);\
delay(500); } }
And is the first part of code on the raspberry pi:
import time
import serial
import struct
ser = serial.Serial('/dev/ttyACM0',9600)
data = 2
time.sleep(2)
print("sending now")
And now, the various attempts of sending stuff over serial, and their corresponding errors:
code: ser.write(data)
error: TypeError: 'int' object is not iterable
code: ser.write(str(data))
error: TypeError: an interger is required
code: ser.write(int(data))
error: TypeError 'int' object is not iterable
code: ser.write(struct('>B', data))
error: TypeError: 'module' object is not callable
Please tell me what I'm doing wrong or what I can do to make this work. I can't think of anything else to put in.
int temp = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.setTimeout(10);
}
void loop()
{
while (Serial.available() > 0)
{
temp = Serial.parseInt();
if (temp == 0)
{
digitalWrite(13, HIGH);
delay(1000); \
digitalWrite(13, LOW);
delay(500);
}
}
if (temp > 0) {
temp--;
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);\
delay(500); } }
And is the first part of code on the raspberry pi:
import time
import serial
import struct
ser = serial.Serial('/dev/ttyACM0',9600)
data = 2
time.sleep(2)
print("sending now")
And now, the various attempts of sending stuff over serial, and their corresponding errors:
code: ser.write(data)
error: TypeError: 'int' object is not iterable
code: ser.write(str(data))
error: TypeError: an interger is required
code: ser.write(int(data))
error: TypeError 'int' object is not iterable
code: ser.write(struct('>B', data))
error: TypeError: 'module' object is not callable
Please tell me what I'm doing wrong or what I can do to make this work. I can't think of anything else to put in.