Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #15 on: November 29, 2011, 12:17:49 am » |
ok i think i am with you so far, but NSS doesnt pick up anything i send out through the arduino serial monitor. nor does it see anything i echo from the router. Could baud rates be a problem? I would think i would at lease see gibberish pop up in the serial monitor. When i say 'console' i mean monitor, btw. How do i set up NSS to make sure it is seeing pin 8? (should have been 8 to begin with, i have fixed that since.) what would the verbiage be? If i type in #define rxPin 8, will the arduino know enough to associate that with NSS?
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #16 on: November 29, 2011, 12:32:00 am » |
How do i set up NSS to make sure it is seeing pin 8? Have a look at the NSS page http://arduiniana.org/libraries/NewSoftSerial/There must be some documentation there. I've never used NSS but in the constructor NewSoftSerial mySerial(8,9); Presumably the 8 and 9 are the Tx and Rx pins (or vice versa). but NSS doesnt pick up anything i send out through the arduino serial monitor. Of course, it's not connected to the PC unless you're running a wire into your laptop  , it's connected to the router. nor does it see anything i echo from the router. You should see something from that if it's transmitting even if the baud rate is wrong (BTW you had 4800 in the original post). How do you know the router is transmitting anything? If i type in #define rxPin 8, will the arduino know enough to associate that with NSS? Nope, that line at present is doing nothing at all, just defining a more human-readable bit of text. For example NewSoftSerial mySerial(rxPin,9); is easier to read than NewSoftSerial mySerial(8,9); ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #17 on: November 29, 2011, 12:40:27 am » |
Of course, it's not connected to the PC unless you're running a wire into your laptop , it's connected to the router. But since NSS is handling the receiving end of things, shouldnt it println whatever comes in to it as well as flicker the light? relaying the info taken from the router to the arduino and then printing it out through the hard tx port into the computer? Or is that wrong? You should see something from that if it's transmitting even if the baud rate is wrong (BTW you had 4800 in the original post).
How do you know the router is transmitting anything? I am running: echo "test' > /dev/tts/1 through the router. yesterday, i opened up two SSH sessions to the router and ran cat < /dev/tts/1 in one and the echo in the other and it echo'd out to itself through the tx pin and into the rx pin just fine. Its the only test i've been able to find, hence the posting here looking for help. I should note that i have tried this on 2 different routers with the exact same effect, so it's not my wiring.
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #18 on: November 29, 2011, 01:18:44 am » |
flicker the light? What light? shouldnt it println whatever comes in AFIAK the NSS Tx pin is not physically connected to your PC or indeed anything else, how can it transmit to it? relaying the info taken from the router to the arduino and then printing it out through the hard tx port into the computer? Or is that wrong? No that's right, but isn't that what the code is doing? Reading from NSS and writing to Serial. and the echo in the other and it echo'd out to itself through the tx pin and into the rx pin just fine. So you did a physical loopback from a TX pin to an Rx pin, you actually connected an external wire. Is that the case? If so (and assuming that today the same test still works) then it's reasonable to say there are characters emanating from the router. I'd still like to see it on an instrument though. Did you figure out the pin 8/9 business. Are you sure you've got the right pin connected? ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #19 on: November 30, 2011, 06:20:48 pm » |
Update. I am sitting here watching the most beautiful thing ever. a flickering green led!. I got it to work with the following code. I think it all came down to having sending on one com port and receiving on another. once i set NSS up to read and standard serial to transmit, it seems to be working... the led part at least. I am going to go through my code now and change things out so that everything reads on NSS and transmits on hardware serial. I'll let you all know how it goes. #include <NewSoftSerial.h> #define LEDpin 13 #define txPin 9
NewSoftSerial mySerial(8,9); void setup () {
Serial.begin(115200); mySerial.begin(9600); pinMode(LEDpin, OUTPUT); }
void loop () { static byte c; if (mySerial.available() > 0) { c = mySerial.read(); Serial.println (c, HEX); digitalWrite (LEDpin, HIGH); delay (100); digitalWrite (LEDpin, LOW); delay (100); }
}
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #20 on: November 30, 2011, 07:18:19 pm » |
YES! Serial communication is a go! Now on to the actual problem. I modified my code with elements from that test sketch so that i can be sure that data is coming through and when i run the carserver client, my light flickers constantly, almost in time with the light on my router. I set this up to println back to the txpin when i have debug turned on and then i used cat < /dev/tts/1 to listen to what was coming across. So basically, the way i see it is that the router is pumping something out, the arduino looks at it and turns around and sends it right back. That data i can see raw in my terminal window... here's the thing. It's just putting out a 0 and a carrige return.... now at some point i had vb6 application that controls the car working to an extent and it put out two 0's and any time i hit a key, it would put out a different number. I cant figure out what has changed. Can you run through my new code and see if i have it set up and reading incorrectly? // include the SoftwareSerial library so you can use its functions: #include <NewSoftSerial.h> #include <ctype.h>
#define DEBUG 0
#define txPin 9 #define rxPin 8 #define LEDpin 13
NewSoftSerial mySerial(8,9); int inByte; // incoming serial byte
#define bit9600Delay 84 #define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94
int serialChar; // stores character of serial Input as integer unsigned long decay; // counter from last command unsigned long decaylimit=100000; // 100,000 is about 5 seconds
void setup() { // define pin modes for tx, rx, led pins:
pinMode(LEDpin, OUTPUT); // set the data rate for the SoftwareSerial port Serial.begin(9600); mySerial.begin(115200); Serial.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 (mySerial.available()) { serialChar = mySerial.read(); mySerial.println((char)inByte); digitalWrite (LEDpin, HIGH); delay (100); digitalWrite (LEDpin, LOW); delay (100); // 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++; } { #if DEBUG // echo for debugging only: Serial.println(serialChar); #endif // 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 case '119': digitalWrite(4, LOW); digitalWrite(7, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); decay=0; break; case '115': digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(4, HIGH); digitalWrite(7, HIGH); decay=0; break; case '97': digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(4, LOW); digitalWrite(7, LOW); decay=0; break; case '100': digitalWrite(4, LOW); digitalWrite(6, HIGH); digitalWrite(5, LOW); digitalWrite(7, LOW); decay=0; break; case '113': digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); decay = decaylimit;
} } } } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35581
Seattle, WA USA
|
 |
« Reply #21 on: November 30, 2011, 07:47:24 pm » |
case '119': This is almost certainly wrong. Either lose the single quotes, or replace the number in the quotes with the correct letter (preferred).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #22 on: December 01, 2011, 12:13:53 am » |
No go. It doesnt move. I think the code is now set up correctly, but maybe the carserver is sending over characters other than wasd? or is the arduino looking for characters in one form and the carserver is sending them over in another? // include the SoftwareSerial library so you can use its functions: #include <NewSoftSerial.h> #include <ctype.h>
#define DEBUG 0
#define txPin 9 #define rxPin 8 #define LEDpin 13
NewSoftSerial mySerial(8,9); int inByte; // incoming serial byte
#define bit9600Delay 84 #define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94
int serialChar; // stores character of serial Input as integer unsigned long decay; // counter from last command unsigned long decaylimit=100000; // 100,000 is about 5 seconds
void setup() { // define pin modes for tx, rx, led pins:
pinMode(LEDpin, OUTPUT); // set the data rate for the SoftwareSerial port Serial.begin(9600); mySerial.begin(115200); Serial.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 (mySerial.available()) { serialChar = mySerial.read(); mySerial.println((char)inByte); digitalWrite (LEDpin, HIGH); delay (100); digitalWrite (LEDpin, LOW); delay (100); // 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++; } { #if DEBUG // echo for debugging only: Serial.println(serialChar); #endif // 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 case 'w': // 119 digitalWrite(4, LOW); digitalWrite(7, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); decay=0; break; case 's': // 115 digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(4, HIGH); digitalWrite(7, HIGH); decay=0; break; case 'a': // 97 digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(4, LOW); digitalWrite(7, LOW); decay=0; break; case 'd': // 100 digitalWrite(4, LOW); digitalWrite(6, HIGH); digitalWrite(5, LOW); digitalWrite(7, LOW); decay=0; break; case 'q': // 113 digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); decay = decaylimit;
} } } } }
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #23 on: December 01, 2011, 12:18:18 am » |
maybe the carserver is sending over characters other than wasd? You tell us, you have a debug print there. But change it to Serial.println(serialChar, HEX); in case you're getting non-printable values. ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #24 on: December 01, 2011, 01:12:50 am » |
Basically, something like this....
0 0 0 0 0 0 0
and so on. nothing else.
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #25 on: December 01, 2011, 01:32:05 am » |
So serialChar is screwed at the point you print it, was it received correctly in the first place. Move you print() around to see where thing start going wrong.
______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #26 on: December 01, 2011, 01:34:09 am » |
Are you really using NSS at 115200? If so what are all the bit9600Delay type constants?
I thought you were using 9600 to the router.
______ Rob
|
|
|
|
« Last Edit: December 01, 2011, 01:35:49 am by Graynomad »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #27 on: December 01, 2011, 01:41:41 am » |
What's a type constant? See how ignorant i am?
I was told by someone (dont know at this point) that the router runs at 115200....
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 73
Posts: 6839
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #28 on: December 01, 2011, 01:55:21 am » |
I was told by someone (dont know at this point) that the router runs at 115200 Hardly confidence boosting  You need to know that. What's a type constant? All these #define bit9600Delay 84 #define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94 But I now see there aren't being used because SWread() never gets called. No matter, you have to identify at what point serialChar is bad. As I said a couple of posts ago Move you print() around to see where thing start going wrong. I see you are echoing the character back to the router, does that work? ______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #29 on: December 01, 2011, 02:06:04 am » |
echoing back to the router does work. It returns 0's as well.
should i remove swread entirely? as well as the type constants? Just to clean things up?
I will try playing with my print debug.
|
|
|
|
|
Logged
|
|
|
|
|
|