i am unable to write my serial.read to input data from a 2nd arduino. the data is trans via serial.print but can't seem to get 2nd uno to read it. the data looks like"||R0000||L0000 view on serial mon from radio
thanks
harry
Have you connected the grounds of the two arduinos together?
Otherwise read the how to use the forum sticky about posting code and post the transmitt and recieve code.
What is a serial mon from radio?
yes the serial output is from a radio and a rec. on usb. it seems that my code isn't right and only 1 byte or digit is processed on the rec.arduino. i was going to post it but i didn't save my code ![]()
any help?
thanks
harry
any help?
Are you serious?
i was going to post it but i didn't save my code
So you want me to help you find the problem with code that even you don't have?
I might be good but I am not that good!
i was working on new code when i read ur post. hope this helps
thanks
#include "MotorMaster.h"
MotorMaster myMotorMaster = MotorMaster();
void setup()
{
myMotorMaster.begin(BUSA);
Serial.begin(9600);
}
void loop()
{
while(Serial.available() == 8);
int R = Serial.read();
int L = Serial.read();
myMotorMaster.drive(COILA, R);
myMotorMaster.drive(COILB, L);
Serial.flush
}
See that cool smilie in your code? Did you put it there?
That is why we ask everyone to post the code in code tags. Please read the how to use the forum sticky.
now that code. What does it do, what do you want it to do?
What on earth is that libary, it is good to provide links to obscure libaries.
Why the serial flush? Look it up, it does not do what you think it does. Generally this command is not needed.
The serial code is written so that when at least one byte is ready to read you read two bytes, smart?
no i didn't put it there it happen when i copy then pasted the code but it is cool.
i am trying to remote control a bot the trans data is |Rxxx |Lxxx. the x are numbers to set dir. and speed the transmit part was easy but to rec. into the 2nd arduino has been a headache for me. only 1 number is rec. and not grouped right. mean while i'll find and read sticky.
thanks
no i didn't put it there it happen when i copy then pasted the code but it is cool.
No it's not cool, it hampers what you are trying to do.
That code only reads one byte so it is no supprise it does that.
Will there always be three x digits or could there be less? If so you need a terminator, something to show the number has finished being sent.
yes i'm sorry it's 4 digits 2 times the first 4 for right wheel and 4 for left and each is preceded by a | then a letter.
when i first looked at building this i didn't look enough and had bought the stuff to make it parts were a walk in the park and other were head banging so many thanks for the help
You need to gather individual serial reads into a char array and then go from there.
Here is some code to help you gather the array:-
I'm starting to understand why Grumpy_Mike is grumpy ![]()
You really need to first learn how to use this forum. There are all sort of neat tool to help communicate your need. There is the URL button that tel us that there is a URL:
go there and you might find this code that will answer most of your questions:
/*
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-anode RGB LED wired like so:
* Red cathode: digital pin 3
* Green cathode: digital pin 5
* blue cathode: digital pin 6
* anode: +5V
created 13 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = 255 - constrain(red, 0, 255);
green = 255 - constrain(green, 0, 255);
blue = 255 - constrain(blue, 0, 255);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}
}
But over all, you should do and analyses all the example that is in the IDE pack, all the base is in there. I know we all like to do the big stuff, but big stuff is a bunch of small stuff put together. So do one step at the time.
I never really got the point of Serial.flush() since it's not really flushing anything.
This has no point, well that I can see.
Waits for the transmission of outgoing serial data to complete.
This was better, at least it's what i expect from a flush function:
(Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)
Why did they change it?
Frédéric_Plante:
I never really got the point of Serial.flush() since it's not really flushing anything.
Well yes it does the definition is:-
Waits for the transmission of outgoing serial data to complete.
So it blocks until the serial output buffer is flushed by the natural process.
This is useful when implementing half duplex communications on the serial port.
Unfortunately beginners seem to think it will wipe out any unread data in the serial input buffer.
So it blocks until the serial output buffer is flushed by the natural process.
Oh! it's a blocking process, I see. Do you know if it "pass the tag" to another process If we use DUE scheduler? I just can't wait to receive my DUE.
So many thing to try, so many answer to gather.
This is useful when implementing half duplex communications on the serial port.
Yeah it's great for EIA-485/RS-485 2 wires com.
Mk, so i'm happy to have read that post, I've learn new stuff today. Thank you Mike. ![]()
here is what i am working now it sends the correct format Rxxxx Lxxxxx but there are tied together i'm tiring to splint them if poss. separate inputs and 1 follows the other and each has its own indicator then something to clear the first if needed still hacking at it
#include "MotorMaster.h"
MotorMaster myMotorMaster = MotorMaster();
String inData;
int R;
int L;
void setup()
{
Serial.begin(9600);
myMotorMaster.begin(BUSA);
}
void loop()
{
while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
if (recieved == '\n')
{
Serial.println(inData);
if(inData == "+++\n"){
}
inData = "";
}
}
}
Since you know the precise length of your strings, what you need is there:
Oh! it's a blocking process, I see. Do you know if it "pass the tag" to another process If we use DUE scheduler? I just can't wait to receive my DUE. XD So many thing to try, so many answer to gather.
I will know tomorow, Finally!!
2014/05/01 21:29 MONTREAL Item process[u]ed[/u]
2014/04/18 12:49 CNXMNA,China International item has left originating country and is en route to Canada
2014/04/06 13:49 362028,China International item mailed in originating country
it will bee the first thing I will try.
still hacking at it
Still not posting code correctly.
It's all a mater of taking the time to read the instructions, and being willing to learn.
If he does not read the instructions on how to use the forum, chances are high that he will not take the time to read the cues I gave him on how to get his problem solved. That is basically why I point where is the answer without giving the answer.
On the other hand with the 2 examples I choosed, if he does take the time to read and analyse, he is going to get more then he bargined for. It is what I call positive reenforcement toward good willing people. ![]()