Show Posts
Pages: 1 ... 104 105 [106] 107 108 ... 244
1576  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.
1577  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]
1578  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);

1579  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?
1580  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?
1581  Using Arduino / Programming Questions / Re: 'ITDB02' does not name a type error on: October 25, 2013, 07:38:20 pm
Quote
hardware make nothing
?
1582  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.
1583  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"?
1584  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).
1585  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

1586  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
}
1587  Using Arduino / Programming Questions / Re: Is there a "split function in arduino? on: October 25, 2013, 12:20:13 pm
I update my reply.
1588  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"
1589  Using Arduino / Programming Questions / Re: GearTooth Sensor on: October 24, 2013, 11:35:27 pm
An ELSE statement might work, or another IF statement where you check to see if it does stall for a second or more.
if(millis() - timer >= 1000)
{
  // set an output pin high
}
1590  Using Arduino / Programming Questions / Re: GearTooth Sensor on: October 24, 2013, 08:51:54 pm
Ok easy, get a reading from the sensor and compare it to an "old" reading. If the two readings are different, then you know it is oscillating.

Example:

Code:
void loop()  {
.
.
.
currentValue = get_from_sensor();

unsigned long timer = millis();
  if(currentValue != oldValue && millis() - timer < 1000) // 1000 = 1 second
  {
    oldValue = currentValue; // they were different and values changed within 1 second, so update old value for next reading
    Serial.println("Oscillating!  "); // show a message that it was oscillating
    timer = millis();                        // Reset timer
  }
}

You could also probably use the pulseIn() function. Set the pin you want to read from, set the state you want to look for HIGH or LOW, and you can also set a timeout value  from 10 microseconds to a maximum of 3 minutes.
Pages: 1 ... 104 105 [106] 107 108 ... 244