Show Posts
Pages: 1 ... 56 57 [58] 59 60 ... 196
856  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 26, 2013, 09:39:35 pm
One more edit. Got rid of the char array and uneeded for loop and added "(char*)buf". this should make things a little easier to understand.
Code:
#include <VirtualWire.h>

void setup()
{
  Serial.begin(9600); // Debugging only
  Serial.println("Receiving");
  pinMode(13,OUTPUT);
  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    digitalWrite(13, HIGH); // Indicate data is being received
    int temp1 = atoi(strtok((char*)buf, ","));  // Look for a comma, the return the data before it.
    int temp2 = atoi(strtok(NULL, ",")); // same as above
    int temp3 = atoi(strtok(NULL, ".")); // Look for a period, then return data before it.
    Serial.print(temp1); // X axis
    Serial.print(", ");
    Serial.print(temp2); // Y axis
    Serial.print(", ");
    Serial.print(temp3); // Z axis
    Serial.println();
  }
  else digitalWrite(13, LOW); // No data received
}
857  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 26, 2013, 05:24:19 pm
Because you want to copy the contents of buf (uint8_t) into a char array. If you tried to use buf directly, it would give errors.
So you need to make sure you have enough space to copy the data. And data[ i ] = buf[ i ] is easy to understand. You could probably also use strcpy();
858  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 26, 2013, 03:14:08 pm
Ok, note I gave you the wrong receiver code before, and I updated it.
859  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 26, 2013, 03:01:29 pm
Code:
Transmitter
[code]#include <VirtualWire.h>

char Array[20];
int X,Y,Z,State;

void setup()
{
  Serial.begin(9600);  // Debugging only
  Serial.println("Sending"); // Debugging only

  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_tx_pin(7); //RF sending pin Arduino Mega
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(5, LOW); // RF ground
  digitalWrite(6,HIGH); // RF Vcc
}

void loop()
{
  X = analogRead(A2) / 4; // X raw data divided by 4 gives 0 - 255
  Y = analogRead(A1) / 4; // -------------------------------------
  Z = analogRead(A0) / 4; // -------------------------------------
  
  sprintf(Array, "%d,%d,%d.",X,Y,Z);
  vw_send((uint8_t*)Array, strlen(Array));
  vw_wait_tx();
}

Receiver
Code:
#include <VirtualWire.h>
char data[20];
void setup()
{
  Serial.begin(9600); // Debugging only
  Serial.println("Receiving");
  pinMode(13,OUTPUT);
  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    //Serial.print("Got: ");
    for (i = 0; i < buflen; i++){
      data[i] = buf[i];
    }
    
    digitalWrite(13, HIGH); // Indicate data is being received
    int temp1 = atoi(strtok(data, ","));  // Look for a comma, the return the data before it.
    int temp2 = atoi(strtok(NULL, ",")); // same as above
    int temp3 = atoi(strtok(NULL, ".")); // Look for a period, then return data before it.
    Serial.print(temp1); // X axis
    Serial.print(", ");
    Serial.print(temp2); // Y axis
    Serial.print(", ");
    Serial.print(temp3); // Z axis
    Serial.println();
  }
  else digitalWrite(13, LOW); // No data received
}
[/code]
860  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 26, 2013, 01:58:30 pm
Nothing can actually be sent at the same time, there is always some delay. However, what you could do is use the sprintf() function. then on the receiving side, use strtok() to break the data up, back into its individual parts.
output[15]; // Or large enough to hold all the characters

strtok(output, "%d, %d.", valThrottle, valBrakes);

861  Using Arduino / Programming Questions / Re: String doesn't accept strtok? on: October 26, 2013, 01:38:01 pm
Quote
All I want is extract the Latidude, Longitude etc (separatelly) from this string...
If you are using this library TinyGPS13.h then you should not need to touch the incoming string. The person who wrote the library made functions that already extract altitude, longitude and latitude for you.
In fact, it comes with an example that does just that.

However, if you are not using the library above, which one are you using? You may just need to upgrade.
Can you provide us with any links as to your GPS module, how its wired, the baud rate your using to communicate with the module, the actual library you have, and above all, post the code you have?
862  Using Arduino / Programming Questions / Re: Unable to compile 'softwareservo.h' sketch on: October 25, 2013, 11:42:04 pm
Could you post the code without the color tags?
863  Using Arduino / Programming Questions / Re: 'ITDB02' does not name a type error on: October 25, 2013, 07:38:20 pm
Quote
hardware make nothing
?
864  Using Arduino / Programming Questions / Re: 'ITDB02' does not name a type error on: October 25, 2013, 05:37:56 pm
There are two Arduino folders, one is a core folder, the other is a sketch folder. The sketch folder is usually located in your "my Documents", that is where you must put/make the libraries folder and put the two graph libraries in it.
865  Using Arduino / Programming Questions / Re: 'ITDB02' does not name a type error on: October 25, 2013, 04:55:11 pm
Could you post the errors?

I wonder if the library still has "Wprogram.h" instead of "Arduino.h"?
866  Using Arduino / Programming Questions / Re: 'ITDB02' does not name a type error on: October 25, 2013, 04:28:58 pm
You need to take the files out of C:\temp, and put them in the proper "libraries" folder.
For instance, mine is "C:\Users\Andrew\Documents\Arduino\libraries". If your Arduino Sketch folder does not have a libraries folder, make one and put the ITDB02 _Graph16 folder inside. You will need to close out the IDE and reopen it.

Also make sure you use #include <ITDB02 _Graph16.h> instead of #include "ITDB02 _Graph16.h"

Added: dc42 beat me to it.

@IQ955
When you get it to work, let me know. I have the same library and I made a few new functions, like draw triangle and radio buttons (round and square).
867  Using Arduino / Programming Questions / Re: String doesn't accept strtok? on: October 25, 2013, 03:04:07 pm
I fixed my example.
Aside from char Str[30] begin too small for the string I wrote, this works fine.
Code:
char Str[60] = "This is a simple NULL terminated string. ";
char * vout;

void setup()
{
  Serial.begin(9600);

  vout = strtok(Str," ");
  while(vout != NULL)
  {
    Serial.println(vout);
    vout = strtok(NULL, " ."); // make sure your split characters looks for something to get the last word, like a period
  }
}

void loop()
{
 
}
Output:
Quote
This
is
a
simple
NULL
terminated
string

868  Using Arduino / Programming Questions / Re: String doesn't accept strtok? on: October 25, 2013, 02:51:52 pm
I needs to be a char array.
Str[30] = "This is a simple NULL terminated string. ";

Also "vout = strtok(allinfo,",");" is just going to output the first word, not the full string. For that you would need a while loop and inside the while loop must be like so.

Edit: I clarified it.

Code:
char Str[] = "This is a simple NULL terminated string. ";
char * vout;

vout = strtok(Str," ");
//print first word
while(vout ! = NULL)
{
  vout = strtok(NULL, " ."); // make sure your split characters looks for something to get the last word, like a period
 // print vout
}
869  Using Arduino / Programming Questions / Re: Is there a "split function in arduino? on: October 25, 2013, 12:20:13 pm
I update my reply.
870  Using Arduino / Programming Questions / Re: Is there a "split function in arduino? on: October 25, 2013, 12:07:39 pm
Yes it is a C string function called "strtok()"
What it does is it reads the buffer and looks for a split character( , . : / ; -   ) really any character you want, and it will output what ever is before the split character.

I can't remember if the buffer needs to be null terminated or not, I think it does.

"Hello, it is 1:20 pm. "
Output = strtok( buffer, ",:" ); //"Hello"
Output = strtok( NULL, ",:" );// " it is 1"
Output = strtok( NULL, ".");// "20 pm"
Pages: 1 ... 56 57 [58] 59 60 ... 196