Go Down

Topic: What happens when you hit "send" in the serial monitor? (Read 898 times) previous topic - next topic

RobDrizzle

I'm having trouble with what I thought was a simple item.

I have a device that is waiting for "s" to be sent via serial before it will start transmitting data.

I assumed the correct way was

Code: [Select]
Serial.print("s\r"); but this does not get the job done.

When pressing enter on the serial monitor, what is actually being sent?

Thanks everyone.

JimboZA

But Serial.print sends from the Arduino to the monitor...

If you mean to send data from the PC to the Arduino, you need Serial.read; something like this:

Code: [Select]
char incomingByte;   // for incoming serial data

void setup() {
       Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
       pinMode(13,OUTPUT);
       digitalWrite(13, LOW);
}

void loop() {

       // send data only when you receive data:
       if (Serial.available() > 0) {
               // read the incoming byte:
               incomingByte = Serial.read();

               // say what you got:
               Serial.print("I received: ");
               Serial.println(incomingByte);
       }
       
        if (incomingByte == 'h' || incomingByte == 'H')
       {
         digitalWrite(13, HIGH);
       }
       else
       {
       digitalWrite(13, LOW);
       }
         
}

Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

RobDrizzle

#2
Jan 27, 2013, 06:06 am Last Edit: Jan 27, 2013, 06:08 am by RobDrizzle Reason: 1

But Serial.print sends from the Arduino to the monitor...




Exactly, I need the arduino to send the "s" command to start communications. Just assume I have two arduinos connected via serial. Unit A is waiting for the "s" command to come from the serial before it will start streaming data to Unit B. Unit B upon boot up will send the "s" command via serial to A to let it know that it is ready. So I do need unit B to Serial.print.

I have tested unit A through the serial monitor and it works fine.

But thank you anyway.

RobDrizzle

Here is the full RX (unit B) code. The TX unit isn't in Arduino IDE code so I'm not going to bother to post it, plus it's really long.


Code: [Select]
#include <TextFinder.h>
#include "PCD8544.h"

TextFinder finder(Serial);
const int NUMBER_OF_FIELDS = 24; // how many comma-separated fields we expect
int fieldIndex = 0; // the current field being received
float values[NUMBER_OF_FIELDS]; // array holding values for all the fields

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
PCD8544 nokia = PCD8544(7, 6, 5, 4, 3);
int batPix = 0; //Pixel for battery graphics
int craftHeading = 0;
int alarmHeading = 0;
int craftAlt = 0;
int alarmAlt = 0;
float craftBattery = 0;
float alarmBattery = 0;

void setup()
{
Serial.begin(111111); // Initialize serial port

 nokia.init();
 nokia.setContrast(45);
 
 Serial.print("s\r");
 
nokia.setCursor(0, 0);
nokia.print("Connecting to Craft.......");
nokia.display();
 
}

void loop()
{
 nokia.clear();
for(fieldIndex = 0; fieldIndex < 24; fieldIndex ++)
{
values[fieldIndex] = finder.getFloat(); // get a numeric value
}
//Serial.print( fieldIndex);
//Serial.println(" fields received:");

craftHeading = values[3]; //Serial.println(" Heading");
craftAlt = values[4]; //Serial.println(" Altitude");
craftBattery = values[22]; //Serial.println(" Volts");

nokia.setCursor(0, 0);
nokia.println("CRAFT    STTNG");
nokia.setCursor(6, 9);
nokia.print(craftHeading);
nokia.setCursor(33, 9);
nokia.print("HDG");
nokia.setCursor(61, 9);
nokia.print(alarmHeading);

nokia.setCursor(6, 18);
nokia.print(craftAlt);
nokia.setCursor(33, 18);
nokia.print("ALT");
nokia.setCursor(61, 18);
nokia.print(alarmAlt);

nokia.setCursor(0, 27);
nokia.print(craftBattery);
nokia.setCursor(33, 27);
nokia.print("BAT");
nokia.setCursor(58, 27);
nokia.print(alarmBattery);

nokia.setCursor(0, 38);
nokia.print("E");
nokia.setCursor(78, 38);
nokia.print("F");

nokia.drawline(8, 36, 69, 36, BLACK);
nokia.drawline(8, 47, 69, 47, BLACK);
nokia.drawline(69, 36, 69, 47, BLACK);
nokia.drawline(8, 36, 8, 47, BLACK);
nokia.drawline(70, 38, 72, 38, BLACK);
nokia.drawline(70, 45, 72, 45, BLACK);
nokia.drawline(73, 38, 73, 45, BLACK);

nokia.fillrect(9, 37, batPix, 10, 1);
nokia.display();

fieldIndex = 0; // ready to start over
}

zoomkat

Quote
When pressing enter on the serial monitor, what is actually being sent?


What is in the text box of the serial monitor is sent, plus the option selected at the bottom of the serial monitor.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

JimboZA

Quote
Exactly, I need the arduino to send the "s" command to start communications.


What's that got to do with hitting send on the serial monitor then?

I'm out...
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

RobDrizzle


Quote
When pressing enter on the serial monitor, what is actually being sent?


What is in the text box of the serial monitor is sent, plus the option selected at the bottom of the serial monitor.


"s" is the only character.

serial monitor options are as follows:

autoscroll is checked
"No line ending" selected
115200 baud rate.

RobDrizzle


Quote
Exactly, I need the arduino to send the "s" command to start communications.


What's that got to do with hitting send on the serial monitor then?

I'm out...


Because I need unit B to act as if it was sending the "s" command from the serial monitor.

zoomkat

Well, the below doesn't match the Serial.begin(111111); // Initialize serial port in your code. If you just want to send an "s", you might try Serial.print('s'); in your code.

Code: [Select]
autoscroll is checked
"No line ending" selected
115200 baud rate.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

RobDrizzle

The 111111 vs the 115200 is because the serial is being done over Xbee and I get errors at 115200. The other unit is also transmitting at 111111. Sorry I forgot to clear that up before.

I noticed that you only used single quotes rather than double quotes. Would that have anything to do with it? I have tried Serial.print("s"); before with no luck.

michinyon

If you are trying to send from arduino B to arduino A,   then what has the serial monitor got to do with it ?

The code you posted for arduino B looks reasonable,  that should send 's' which is what you want to do.

I could suggest two things.   

You don't need the carriage return.
You could add a delay after the Serial.begin() in case the device needs to time to start up.
You could connect arduino B to the PC to see if you get the 's' there on the serial monitor.  If not,  figure out why.
Make sure the TX and RX are connected the right way round.
If it doesn't work, try the other way round. I've had some devices labelled wrongly.

michinyon

Quote
I noticed that you only used single quotes rather than double quotes. Would that have anything to do with it? I have tried Serial.print("s"); before with no luck.


The difference is that 's' is a char  and "s"  is a char array which has only one char in it.

RobDrizzle

Sorry gentlemen if I am causing confusion by referring to the serial monitor. I have confirmed that both units will talk and respond accordingly using the serial monitor. Unit A will start streaming data after the "s" is sent and unit B is indeed sending the "s". The original question linking the serial monitor to the serial arduino communication was that both units work individually through the monitor but not together without it, hence, was there something extra sent by the serial monitor that I was not replicating with the code.

Go Up