Show Posts
Pages: 1 [2] 3
16  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 13, 2012, 03:43:45 pm
What should I do to send bytes instead of integer? Which code would work better? I use byte() to convert it right? And from byte to integer?
17  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 12, 2012, 02:47:00 pm
Everything is working!!! no problems transmitting nor receiving, it works just perfectly! thank you really much smiley
But sadly I have another question, I don't know if I should post it on another topic but I will ask here before. The code work fine, it doesn't seem to have problems but as it is running every 5-6 ultra fast cicles it does one really slow. Since my robot is a car it's a big problem the fact that I can have long delays between orders and execution of them. Can you suggest me something or dou you have any advice about how to keep the running stable? smiley
18  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 09, 2012, 10:29:58 am
Now I understand, I've written a Sh*tty code, I have to write everything again. I have to use the commas to understand if there is a new number instead of using pre-fixed position (as here with the loop). I used the loops to take out what i needed, but i used them in the wrong way and as i checked for the incoming data with
Code:
Serial.print(serialcom[i]);
i didn't though tha i would have read4 time the same number. This part could work if I used
Code:
Serial.print(serialcom[j+i]);
  Now I have to:
-rewrite this bad code
-cut out all the loops and use some more efficient way to separate the data

Thank you really much, I was too focussed on the wrong way to realize it was a quite obvious stupid error. Sorry again for the bad english, bad code and everything else smiley I'm new to arduino and i have to get used to use it and touse the support of the forum!
19  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 09, 2012, 10:08:41 am
I thought it was the best way to create an unique string to send. I don't have any idea, which way is the best way to send them. How should I do it? Which is the best way to send those numbers?
20  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 09, 2012, 09:16:29 am
the sending code:
Code:
#include <SoftwareSerial.h>

const int x=2;
const int y=1;
const int z=0;
int sx=0;
int sy=0;
int sz=0;
String datapac="";
SoftwareSerial mySerial(10, 11);

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(x,INPUT);
  pinMode(y,INPUT);
  pinMode(z,INPUT);
  pinMode(10, INPUT);
  pinMode(11, OUTPUT);
}

void loop()
{
  sx=analogRead(x);
  sy=analogRead(y);
  sz=analogRead(z);
  sx=map(sx,0,1023,0,255);
  sy=map(sy,0,1023,0,255);
  sz=map(sz,0,1023,0,1);
  delay(10);
  datapac += "<";
  datapac += String(sz);
  datapac += ",";
  datapac += String(sx);
  datapac += ",";
  datapac += String(sy);
  datapac += ",";
  datapac += String(200);
  datapac += ">";
  /*if(Serial.available()>0)
  {*/
    Serial.print(datapac);
    mySerial.print(datapac);
  /*}*/
  delay(20);
  datapac="";
}
the reading/control code:
attached to the post.
21  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 09, 2012, 08:47:21 am
I send a string from the other arduino. It's like c=<1,123,123,200> and in the code I wrote Serial.print(c). So in the end do I have to give some delay somewhere? Or should I send the data I want not as a string?
22  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: December 09, 2012, 05:25:55 am
I have a little question: as I use the serial.read() function, does it need some time to delete the readen data or is it immediate? I've had some trouble because as I send something like 1,2,3 with the code you gave me I receive 1111,,,,2222,,,,3333 and I'm wondering if it's a problem with some delay() I should use. I simply read the data and put them in one array, should I use some delay to give my board the time do read and then clear the data?
23  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 20, 2012, 05:23:15 am
I need to have always the more recent data sent, so that the car has the latest command i gave her, If the buffer fills quicker than arduino reading it's data I would have always an encreasing delay from my commands and what the robot does, isn't it?

Now as I'm writing about this I've thought:I could add a part of code that sends an "ok" when it's ready to recive, so the ground station sends it's data and the car recive only those one, leaving the buffer clear when I don't need data and ready to recive as I have to use them. would that work?

My first idea was: ground station continues sending data, car reads the latest sent. I clear the buffer so that the data aren't too old
Now: car needs data, send a byte to the G.station, which sends back the array of data needed. No useless communication, no buffer filling up with data i don't need ,as you said, REALLY the latest data availale.
Right?
24  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 19, 2012, 09:34:14 am
The code was the one you send me, but i fixed the problem, it was simply an error with #define (I've written #Define x=2 as I added you part to my code, then I've seen my huge mistake).
Now, you said me I do not understand Serial communication, it's right, as I wrote Serial.flush() I was trying to clear the buffer, so that the data will be the newest possible. How does I clear the buffer?
Thank you for your help!
25  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 07, 2012, 11:47:12 am
Strange, when using this code the compiler gives me an error on the if and else if statement (expected primary expression before '=' token) but i double checked the whole code and I didn't found anything :S
26  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 07, 2012, 11:08:56 am
thank you so much, I was really panicking smiley sorry for the bad code and bad comments :S next time I'll be more careful with them!
I'll try to complete the code and let you know if it worked smiley
27  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 07, 2012, 10:21:34 am
ok now I'm writing another program...I'm working with strings I'll post it when I'm finished. By the way: i know my comments are quite bad,but it's because you don't have the image of my robot...the problem is that the angles that I write aren't the same as the one of the servo (there is a ~5° difference) smiley
Thank you for the problem with long-float, I hadn't noticed, I'll fix it now.
For the problem with the sending code i've attached it to my third comment (it was with the second one but somenthing hasn't worked)
And for the last problem:I had changed this part of my code but i wanted not to save those changes, but when i've closed arduino i might have saved them by mistake, sorry smiley

Maybe is better just to start with a new code, so it'll be easier for you to help me: I have had a new idea:I "pack" a string with all the data,i send it trough the xbees and than unpack it.
the idea was a string like that: "ST;z=***x=***y=***END", where *** can be numers from 0 to 255. I packed it succesfully and seems to work. now I have to unpack it. the two programs are attached
28  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 07, 2012, 09:32:28 am
and sorry but I'm not really good with arduino, specially with serial and with xbee
I'm a noob and this is my first big project smiley
29  Using Arduino / Networking, Protocols, and Devices / Re: send array of integers via xBee s1 on: October 07, 2012, 09:27:37 am
the code of the car is ctrl_robot_....1_7_2, the one of the ground station is ctrl_xbee_...
short explanation for the car code:
float ping(): read the distance from the objects (used in automatic mode only)
void resetdirezione(angolatura): set and move the wheels to the specified angle
void direzione():decides which is the best direction (R or L)
--> int leggiseriale(): this is where the problem should be: this function has to read the data coming from the xbee and separate them in one array so that i can use the numbers easily
//void cercacasa(): unused at the moment (should seek IR and find home)
void destra() and void sinistra(): turn the wheels right or left (instead of them now i use resetdirezione(angle))
setup()smiley-small..
void loop():read the data from the xbee and set the mode: if spia==0 the car moves on automatic mode (with HC-SR04 sensor), else it should use the numbers it gets from xbee to move)
short explanation for the ground station code:
i read the values from a playstation controller (just from 2 potentiometers and one button), than i send them: sz=car mode, sx=FW/BW,sy=R/L,200= default speed (for automatic mode)
if u need more explanation i will give you every info you need smiley
ps.the code, since leggiseriale()gives me back always 0, so automatic mode, works perfectly, the problme is that i want to use also the other mode
thank you
propilot
30  Using Arduino / Networking, Protocols, and Devices / send array of integers via xBee s1 on: October 07, 2012, 08:27:21 am
Hi,
I have some problems sending 4-5 data via xbee.
I'm using arduino mega 2560, arduino diecimila, 2 xbee s1 and I want to control a RC car using those chips. the data I'm trying to send are: status (car on automatic mode or RC mode, values are 0 or 1), FW/BW ( car moving forward/backward, values from 0 to 255, 125-135 is not moving), direction (richt left, values from 0 to 255, which represent the angle of the wheels), default speed (which is the speed of the car when moving on automatic mode).
Until now I've had lot of troubles, because I don't really know how to send an array trough xbee and every time I write a new code it doesn't work. do someone an help me please? I haven't found anything yet and I'm quite desperate :S
thanks
propilot
Pages: 1 [2] 3