Go Down

Topic: serial communication problem on arduino (Read 548 times) previous topic - next topic

aouate3

I have a Arduino Uno, and a Linksys wrt54gs v4 router that is running OpenWRT, i am having a issue, i need to send serial data from the router to the arduino, i have the arduino conencted up to the router, the serial pin header on the router  is conencted dirrectly to the arduino

router gnd <-----> arduino gnd
router TX <------> Arduino RX
router RX <------> Arduino TX

it was working perfectly, with my script before i had to reflash the firmware on the router..

the serial port on the router is fine, if i connect the routers RX and TX lines together and open up 2 SSH sessions, one with the command "cat /dev/tts/1" and on the other "echo test > /dev/tts/1" i get the text "test" on the cat window

on the arduino, same deal, serial works fine.

when i have this sketch running on the arduino, the arduino easily recieves the serial data


Code: [Select]

void setup () {
}

void loop () {
}


but when i have this sketch running on the arduino

Code: [Select]



#define DEBUG 0
#define WAIT_FOR_START 1

unsigned char incomingByte = 0;
unsigned long loop_count = 0;
unsigned char horn = 32;
unsigned char redLED = 64;
unsigned char BlueLED = 128;
unsigned char FireWeapon = 4;

unsigned char LeftForward = 1;
unsigned char LeftReverse = 2;
unsigned char RightForward = 4;
unsigned char RightReverse = 8;

unsigned char PORTB_val;
unsigned char PORTD_val;

unsigned char in_char = 0;

void setup()

{




//PORTD = digital IO 0-7
//FireWeapon, horn, redLED, BlueLED

  pinMode(4, OUTPUT);    // sets the digital pin as output
  pinMode(5, OUTPUT);      // sets the digital pin as output
  pinMode(6, OUTPUT);      // sets the digital pin as output
  pinMode(7, OUTPUT);      // sets the digital pin as output

//PORTB = digital IO 8 - 13 
//LeftForward, LeftReverse, RightForward, RightReverse

  pinMode(8, OUTPUT);      // sets the digital pin as output
  pinMode(9, OUTPUT);      // sets the digital pin as output
  pinMode(10, OUTPUT);     // sets the digital pin as output
  pinMode(11, OUTPUT);     // sets the digital pin as output
 
  Serial.begin(9600);      // set up Serial library at 9600 bps
 
  PORTD = redLED;    // turn on the red LED
 
  #if DEBUG
flash_led(3,500);
  #endif
 
  wait_for_start();  //Waits for startup message from router serial port
//continues after receiving it.
}


void flash_led(unsigned int count, unsigned int rate)
{
// debug routine that flashes an LED

int n_count = 0;

while (n_count < count)
{
   n_count++;
   digitalWrite(13, HIGH);       // sets the LED on
   delay(rate);                  // waits for a bit
   digitalWrite(13, LOW);        // sets the LED off
   delay(rate);                  // waits for a bit
}
}

char get_char()
{
//Function that waits for a character from the serial port
//If none are received, it returns 0.
//The timeout is so that if the router stops sending data to the microcontroller,
//the micrcontroller will stop driving the car, rather than just going forever with
//the last command.  Timeout is around 250mS.

  while (loop_count < 30000)
  {
    loop_count++;

    if (Serial.available() > 0)
    {
      incomingByte = Serial.read();
      loop_count = 0;
      return incomingByte;
    }
  } 
 
  loop_count = 0;
 
  #if DEBUG
        Serial.print('X', BYTE);
  #endif
 
  return 0;
}

unsigned char wait_for_start()
{
//Waits for startup message from router serial port
#if WAIT_FOR_START

  #if DEBUG
    Serial.println("Waiting...");
  #endif

  while(1)
  {
    if (get_char() == 'j' && get_char() == 'b' && get_char() == 'p' && get_char() == 'r' && get_char() == 'o')
  {
   
  #if DEBUG
      Serial.print("Start Code Recieved");
  #endif

      return 0;
    }
  }
#endif
}

void loop()   


//Function that processes input from serial port and drives the Robot based
//on that input.

  in_char = get_char();
 
  //Split byte received in to upper and lower halves.
  PORTB_val = in_char & 0x0F;
  PORTD_val = in_char & 0xF0;
 
  //Make sure the BlueLED is turned on now.
  if ((PORTD_val & BlueLED) == 0)
  {
    PORTD_val = PORTD_val + BlueLED;         
  }
 
  //The following IF statements are sanity checks to make sure that LeftForward and LeftReverse cannot be on at the same time
  //and that RightForward and RightReverse can't be on at the same time.
  if ((PORTB_val & (RightForward + RightReverse)) == (RightForward + RightReverse))
  {   
    PORTB_val = PORTB_val - RightReverse;   
  }
 
  if ((PORTB_val & (LeftForward + LeftReverse)) == (LeftForward + LeftReverse))
  {
    PORTB_val = PORTB_val - LeftForward;
  }

  //Write the processed values to the ports.
  PORTD = PORTD_val;
  PORTB = PORTB_val;

  #if DEBUG
    Serial.print(PORTD, HEX);
    Serial.print(PORTB, HEX);
  #endif

}



the arduino doesnt even acknowledge that i have sent serial data to it, even if im running the arduino off its own power supply..

anyone know how i can fix this?

baum

Quote
arduino easily recieves the serial data



I don't see how your first sketch could do anything.

James C4S

Your troubleshooting steps aren't adding up to me.

You say the first sketch easily receives data on the Arduino.  However, it does nothing.

You also say that the only change you've made (or the only change you've mentioned) is the firmware on your router.  So if you changed something on the router, why would you suspect the Arduino is the problem?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

aouate3

the first sketch makes it act like a serial gateway, and the arduino IDE running on my computer can see the serial data it is picking up, the second sketch actually listens to the serial data and does stuff.

James C4S

#4
Oct 08, 2011, 07:41 pm Last Edit: Oct 08, 2011, 07:49 pm by James C4S Reason: 1
Quote
the first sketch makes it act like a serial gateway, and the arduino IDE running on my computer can see the serial data it is picking up

No, the first sketch does absolutely nothing.  I don't know what you mean by "serial gateway" or what serial data is getting "picked up."
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

aouate3

ok first off, im 16, second, using that first sketch, it basically doing the same as removing the atmega chip from the arduino board

imagine a arduino uno development board without a atmega chip, what does that leave you with?

a ftdi chip, aka TTL SERIAL TO USB! i have the usb cable connected to the arduino, then to a computer, on the computer, i am using the Arduino IDE and the serial monitor tool on the Arduino IDE. I am doing this so i can test my setup to see if the data being sent from the linksys wrt54g's serial header is being recieved by the arduino, which it is... UNTILL i upload my second sketch to the arduino, at that point i dissconnect the usb cable from the Arduino UNO and connect up a 6 volt wall adapter to the Arduino so that the arduino is still getting power

i send a command to the arduino, using the ssh console on the router, by using the command " echo jbpro > /dev/tts/1 ", but the arduino doesnt recieve serial data.


aouate3


Your troubleshooting steps aren't adding up to me.

You say the first sketch easily receives data on the Arduino.  However, it does nothing.

You also say that the only change you've made (or the only change you've mentioned) is the firmware on your router.  So if you changed something on the router, why would you suspect the Arduino is the problem?


because its not working, and the sketch might of got messed up for all i know, i have a few different revisions of it, and some got lost, so im working with what i have.

zoomkat

Quote
ok first off, im 16,


OK, so you probably haven't developed good logical thinking yet.

Quote
because its not working, and the sketch might of got messed up for all i know, i have a few different revisions of it, and some got lost, so im working with what i have.


Yes, that is all messed up. Test your arduino using the serial monitor. When that is working, then work on your router. Your problem started when you flashed the firmware. Maybe you should go back to the previous version and see what is different. Maybe the baud rates are different and such.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

aouate3


Quote
ok first off, im 16,


OK, so you probably haven't developed good logical thinking yet.

been working on electronics since i was 3, understood the concepts of circuitry and built my first circuit (consisting of 4 switches, 2 leds, a motor, and a buzzer) without guidance or help AT ALL when i was 4. been repairing computers and building random electronics since then. i can diagnose most computer problems in under 4 minutes. you tell me if ive developed good logical thinking yet

And after looking over my sketch, it was a issue with my sketch, my wiring was perfect, everything was perfect except for a error in my sketch.

Its working now. Good Day..

James C4S

#9
Oct 08, 2011, 08:30 pm Last Edit: Oct 08, 2011, 08:34 pm by James C4S Reason: 1

ok first off, im 16

So?  I'm 5'9".  What do your age and my height have to do this discussion?  Nothing.  


And after looking over my sketch, it was a issue with my sketch, my wiring was perfect, everything was perfect except for a error in my sketch.

It is always helpful to others if you can explain what the actual problem was (and ideally how it was solved.)  In case others have the same issue.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

zoomkat

Quote
been working on electronics since i was 3, understood the concepts of circuitry and built my first circuit (consisting of 4 switches, 2 leds, a motor, and a buzzer) without guidance or help AT ALL when i was 4. been repairing computers and building random electronics since then. i can diagnose most computer problems in under 4 minutes. you tell me if ive developed good logical thinking yet

And after looking over my sketch, it was a issue with my sketch, my wiring was perfect, everything was perfect except for a error in my sketch.



Since you haven't mastered punctuation and capitalization yet, one would expect you to have problems with code.  :)
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up