Society of Robots - Robot Forum

Software => Software => Topic started by: Henrique on October 16, 2010, 12:10:07 PM

Title: Help! How send/receive data from axon 1
Post by: Henrique on October 16, 2010, 12:10:07 PM
Hi again   :-X
how can I send/receive data for the axon??? through the UART
Thanks anyone who can help!
Title: Re: Help! How send/receive data from axon 1
Post by: knossos on October 16, 2010, 05:51:39 PM
Have you read this yet?  SoR Microcontroller UART tutorial (http://www.societyofrobots.com/microcontroller_uart.shtml)

Alternatively you can use WebBot's Project Designer and assign the output to the UART for a quick output.
Title: Re: Help! How send/receive data from axon 1
Post by: Henrique on October 17, 2010, 01:38:31 PM
hmm, but in case of a connection, for example I need to send some data from the axon to my computer and then send a given computer to the axon. Since this connection is only over when I turn off the axon. Which method do you recommend?
and I need to buy extra hardware for this?
I already do connect to the axon via the usb of my computer.
Title: Re: Help! How send/receive data from axon 1
Post by: knossos on October 17, 2010, 06:04:12 PM
UART is bidirectional.  You can use the single USB connection and communicate bidirectionally across it.  If you look at WebBotLib's servosCenter() it gives an example of this.
Title: Re: Help! How send/receive data from axon 1
Post by: Henrique on October 17, 2010, 11:58:00 PM
Humm alright!
Thanks a lot!
Title: Re: Help! How send/receive data from axon 1
Post by: Admin on October 18, 2010, 08:05:44 AM
These should also help:
http://www.societyofrobots.com/programming_data_logging.shtml (http://www.societyofrobots.com/programming_data_logging.shtml)
http://www.societyofrobots.com/electronics_bluetooth_robot.shtml (http://www.societyofrobots.com/electronics_bluetooth_robot.shtml)
Title: Re: Help! How send/receive data from axon 1
Post by: Henrique on October 27, 2010, 06:39:08 PM
enjoying the topic

I'm programming a serial communication by the Windows API, and I have this code sending an array int to the serial port (COM), and I read the response (by the axon) in the console
  
Code: [Select]
  DWORD BytesLidos = 0;
   int count1=0;
   int count2=100;
   uint8_t c[LEN_BUFFER];
   while(ReadFile( hCom, c, LEN_BUFFER, &BytesLidos, NULL )){
  cout <<"data1: " <<(unsigned short)c[0]<<"\n";
  cout <<"data2: "<< (unsigned short)c[1]<<"\n";
    DWORD BytesEscritos = 0;
  int send[2];
  send[0] = ++count1;
  send[1] = ++count2;

  WriteFile( hCom, send,2, &BytesEscritos, NULL );


   }

in AVRStudio I tryed to read the data from the serial port and send back them to read in the console in the programm above. Unfortunately I can only get the first byte stored, the second byte I can't, my question is how to receive an array of bytes sent by port com.

Code: [Select]

                uint8_t data[2];

data[0] =  GET_DATA_USB;
data[1] =  GET_DATA_USB;

uartSendBuffer(UART1, data, 2);
Title: Re: Help! How send/receive data from axon 1
Post by: Admin on October 28, 2010, 02:33:11 PM
in AVRStudio I tryed to read the data from the serial port and send back them to read in the console in the programm above. Unfortunately I can only get the first byte stored, the second byte I can't, my question is how to receive an array of bytes sent by port com.

This is how I put received data into an array:
Code: [Select]
char command[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

//this function stores uart data into an array
//a 'r' character signals the end of a command
void get_wireless_command(void)
{
int data;
uint8_t count=0;

data = ZigBeeGetByte();//read from your UART

if(data!=-1)//check for wireless command
{
while(data!='r')//if command is not complete
{
if(data!=-1)//if data is available
{
command[count]=data;
count++;
}
data = ZigBeeGetByte();
}

//store the r, since it already left the loop
command[count]=data;

process_command();//data recieved, now update state
}
}