Reputation: 111
I am using Arduino Nano to serial communicated with ODROID (single-board computer installed Ubuntu 14.04). The Arduino code:
void setup() {
Serial.begin(9600); // set the baud rate
Serial.println("Ready"); // print "Ready" once
}
void loop() {
char inByte = ' ';
if(Serial.available()){ // only send data back if data has been sent
char inByte = Serial.read(); // read the incoming data
Serial.println(inByte);
}
delay(100); // delay for 1/10 of a second
}
The Python code in ODROID:
#!/usr/bin/env python
from time import sleep
import serial
ser = serial.Serial('/dev/LIDAR', 9600, timeout=1) # Establish the connection on a specific port
sleep(1)
print "Arduino is initialized"
counter = 32 # Below 32 everything in ASCII is gibberish
while True:
if (ser.inWaiting()>0):
counter +=1
ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino
print ser.readline() # Read the newest output from the Arduino
sleep(.1) # Delay for one tenth of a second
if counter == 255:
counter = 32
ser.close
Traceback(most recent last):
File "./serial_test1.py", line 16, in <module>
print ser.readline() # Read the newest output from the Arduino
File "/usr/lib/python2.7/dis-package/serial/serialposix.py", line 43, in read
buf = os.read(self.fd, size-len(read))
OSError: [Errno 11]Resource temporarily unavailable
Then I had this issue after print some values, I know this problem maybe no data in available at current time. But how can I figure out this issue. Thanks for your help.
Upvotes: 2
Views: 8097
Reputation: 1566
You are receiving this error since your serial device is being used by os itself. You should stop os to use this device.
Serial getty is now a service and you should stop and/or disable it:
sudo systemctl stop [email protected]
sudo systemctl disable [email protected]
Note that my native serial device id is ttyAMA0.
to permanently disable serial service, use sudo systemctl mask [email protected] in this case serial service will not start even on reboot.
Upvotes: 1
Reputation: 2120
I don't know if this will work for ODROID, but I found a post about similar problem with Raspberry PI. In that post one of the answers redirected to this link
There it says the problems is caused by Raspberry Pi serial port, which is used by default to use the system console which conflicts when you try to use it for your own purposes
To disable the serial por for console you must edit the file /etc/inittab
and comment the line T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
(You comment it with a #
at the begining of the line, like in python). You must reboot the ODROID and it should work
I suggest you to read the answer I linked cause it explains a bit more about how can you substitute the serial port to access the command line (It suggests using ssh) and another thing is that Raspberry PI (And assume ODROID works similar) sends at boot time a message through serial port that will be received by the Arduino. You can remove that message and it's explained there
Hope this helps you
Upvotes: 1