Ok guys, here's the setup
Computer -> wifi - > wrt54gs linksys router -> sparkfun logic level converter to 5v -> Arduino software serial on pins 8 and 9 on a Seeeduino board -> DFrobot dual H bridge driver shield -> tyco rebound RC chassis (same drive style as a tank chassis).
I can send data over serial from the arduino and using cat < /dev/tts/1 my router can see it in SSH. I cannot get data to send the other way to the arduino. In order to get commands to the h bridge and from there to the motors, i need to send data through the router over serial to the arduino.
This is based off of Jon Bennett's project (Wifi Robot - JBProjects.net)
Here is my code. I have tried 2 different routers with the exact same result. I am sure at this point it is a matter of coding to get my arduino to see the serial data. Jon had mentioned something about calling SWread to me, but i dont know enough about linux or processing to do this right. Can you guys give me a hand here? Again, If i set up a sketch to println something like "hello", i can see it just fine over ssh or telnet on the router. It's the communication going the other way that is necessary, and of course the one thing that isnt working for me.
Code:
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
#include <ctype.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
int serialChar; // stores character of serial Input as integer
int serialLoop; // counter for serial read loop
unsigned long decay; // counter from last command
unsigned long decaylimit=100000; // 100,000 is about 5 seconds
#define rxPin 8
#define txPin 9
#define ledPin 13
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte pinState = 0;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello"); // For debugging purposes
//left/right motors
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
//end debugging
}
int SWread()
{
byte val = 0;
while (digitalRead(rxPin));
//wait for start bit
if (digitalRead(rxPin) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rxPin) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}
void loop() {
//check for serial communications
if (SWread() > -1) {
// decay counts the age of the last command
// at the limit (100,000 = ~5 seconds, all signals are shut off
if (decay > decaylimit) {
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
// stop counting at limit, shut off all pins
}
else {
decay++;
}
// this loop read whole strings. as soon as a string is detected
// each character is evaluated. We only care about the first one.
for (serialLoop=0; serialLoop < 16 && Serial.available(); serialLoop++) {
serialChar = Serial.read();
// echo for debugging only:
mySerial.print(serialChar);
// only do evaluation on the first letter (first loop)
if (serialLoop==0) {
// serialChar contains the ASCII code of the *first* character sent over serial when defined as int
switch (serialChar) {
// logical signals w s a d style any change shuts off previous command
case 119: //w - forward, pin 6+8
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
decay=0;
break;
case 115: //s - backwards, pin 7+9
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
digitalWrite(5, HIGH);
digitalWrite(7, HIGH);
decay=0;
break;
case 97: //a - left, pin 6+9
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
decay=0;
break;
case 100: //d - right, pin 7+9
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
decay=0;
break;
case 113: //q - stop, pin 6+7+8+9 off
digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW);
decay = decaylimit;
break;
}
}
}
}
}