I'm trying to get an arduino to talk with a beaglebone black. I have followed this tutorial for getting ttyO4 open on the BBB and used the following command on to set the serial line correctly:
wiring is set up according to this tutorial. stty -F /dev/ttyO4 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
next data is sent using the following method:
echo s123 > /dev/ttyO4
the arduino uses the followingvoid loop(){ code to check for serial communication:
#include <SPI.h>
void setup(){ //////////////SETUP///////////////////////
Serial.begin(9600);
}
void loop(){
if(Serial.available()>=4){
digitalWrite(12, HIGH);
delay(1000); // wait for a second
digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(12, HIGH);
byte b1,b2,b3,b4;
b1=Serial.read();
}
}
}
However it seems no message is received. It does not give any error either.
As an alternative I have also tried a variant of the code suggested in the wiring tutorial resulting in the following code:
import sys
from bbio import *
Serial2.begin(9600)
for arg in sys.argv:
print arg
Serial2.write(arg)
delay(5)
called with pyton test s123
this printed s123 but the arduino remained silent.
Edit I have now also tried to exactly follow the wiring tutorial so that gave me the following sketch:
char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT); // digital sensor is on digital pin 2
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(500);
}
void loop()
{
Serial.write("A");
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
if (Comp("A")==0) {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(500);
}
}
char Comp(char* This) {
while (Serial.available() > 0) // Don't read unless
// there you know there is data
{
if(index < 19) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
if (strcmp(inData,This) == 0) {
for (int i=0;i<19;i++) {
inData[i]=0;
}
index=0;
return(0);
}
else {
return(1);
}
}
and on the BBB we turn on the echo script with
/PyBBIO/examples$ sudo python serial_echo.py
The effect remains that there is no error but also no data delivery.
setup ()
and any declarations also -- ie show a whole arduino sketch that you used. That will allow people to run tests and diagnose problems. Also the built-in LED is on 13 not 12 so say if you wired an extra LED or something. $\endgroup$