.write() not working?

Hi guys,

I’m trying to UART send some data to my Arduino. I can post data to the imp and read it fine. But when I try the other way around I get nothing on the Arduino end. I have triple checked the connections and seems fine.

The scenario I’m testing is the HTTP in form post. I used the documentation example and I’m receiving the value from the form fine.

I then trying to use that value to send to the Arduino.

class impeeIn extends InputPort
{
name = “UART Out”;
type = “string”;

function set(v)
{
    hardware.uart57.write("Hello, World!\\r\

");
server.log("v.x: “+v.x+” v.y: "+v.y);

}

}

Just to debug I’m sending Hello World across but no love. Is there anything obvious I’m missing in this piece?

On the Arduino end I’ve got

 if (impSerial.available()) {
      command2 = impSerial.read();
   
     Serial.println("RECEIVED"); //valve 
     Serial.print(command2); //valve 
 }

Getting nothing though.

Are you level shifting the signal? The imp is outputting 3.3v, and the arduino is running at 5v.

Generally, this shouldn’t be an issue as the ATMEGA Vih(min) is 3.0v (ie, the minimum voltage it wants to see to accept the input as a logic 1), but…

You have got the grounds connected together too, right?

I think so. I’m sending data to the imp through the Arduino no problem.

I’m using the Sparkfun shield as the interface.

https://www.sparkfun.com/products/11401

‘The Shield connects one of the imp’s UARTs (Imp pins 5 and 7) to either the Arduino hardware UART or a software serial on pins 8 and 9’

I’m using software serial: SoftwareSerial impSerial(8, 9);

I just tried another Arduino to rule that out and still no luck.

This should send “1” via serial yeah? From pin 5 to RX pin on the Arduino?

hardware.uart57.write(“1”);

sorry to ask these basic questions but…

have you also checked that you can get other serial reports back from Arduino?

is your receiving code inside loop ? You didn’t paste the whole code so we cannot see that.

I have not used software serial but i have used the sparkfun shield board. I jumpered to the hardware serial in my application.

the .read returns one character and it seems you know that.

I don’t know if it matters but maybe on imp side you should write ‘1’ instead of “1”.

The shield does the level shifting which helps with function - unless there is a fault in the hardware.

You can write ‘1’ (character) or “1” (string) with uart.write() these days - that feature was added a while back.

It does sound like either a problem with your software serial setup, or with the sparkfun shield.

I have an Xbee communicating with the Arduino on software serial

SoftwareSerial mySerial(2, 3); //xbee
SoftwareSerial impSerial(8, 9); //impee

Can send and receive on the xbee serial and can send with the impee serial. Just can’t seem to receive back on the impee RX pin 9.

I tired a different Arduino and replacing the cable between pin 5 on the imp and pin 9 Arduino.

Must be something simple I’m missing because it should be simple to get this working.

I might try through a breakout board for the imp. See if its the shield.

You have a voltmeter? Check the voltage on the pin 9 of your arduino. Should be 3.3v (serial idles high)

Just tested with the voltmeter on the sparkfun shield. Reading about 4.5v on both the impee pins 5,7 and Arduino 8,9

Hmm. Ok, how about you do

hardware.pin8.configure(DIGITAL_OUT);
hardware.pin8.write(0);

…to drive the pin low, and see what the soft serial RX pin on the arduino reads in that case?

I found out why… :slight_smile:

I didn’t have impSerial.listen() in the setup kicks self

Now I’ve broken my Xbee posting to the impee playing around with the code :smiley:

Fun and games… sigh

ummm… If I have two .listen() then only 1 works… Looks up the documentation and should work with two.

Have to put them in the Loop function. But doesn’t want to work. Even tried on the same baud rate.

http://arduino.cc/en/Tutorial/TwoPortReceive

If you read the example code in there, it says it can only listen on one at a time:

“In order to listen on a software port, you call port.listen().
When using two software serial ports, you have to switch ports
by listen()ing on each one in turn. Pick a logical time to switch
ports, like the end of an expected transmission, or when the
buffer is empty. This example switches ports when there is nothing
more to read from a port”

…which is why real serial ports rock, and why we have 3 of them on the imp and 4.5 of them (one is RX only) on the module!