Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: extract data from serial.print on: March 22, 2014, 10:35:20 am
Thanks for pointing me in the right direction
2  Using Arduino / Programming Questions / extract data from serial.print on: March 22, 2014, 09:55:10 am
I have used the basic sketch for the RF22 module, and I can push a button on the server and have it print specific stuff on the client radio Arduino.  using the basic sketch I am able to Serial.print the incoming data, but cannot figure out how to capture that data into an array for control purposes.

Code:
uint8_t buf[RF22_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);


    if (rf22.waitAvailableTimeout(500))
    {
      // Should be a message for us now   
      if (rf22.recv(buf, &len))
      {

        Serial.print("got reply: ");
        Serial.println((char*)buf);
        char inData[24] = {
          (char*)buf        };
      }

I tried the char inData[24] = { (char*)buf }; to store the Serial data into an array and got  a

invalid conversion from 'char*' to 'char' error
3  Using Arduino / Programming Questions / Re: converting a 0 to 000 for bluetooth transmit on: March 14, 2014, 12:04:30 pm
Hello Mark,
     Big thank you, figured out how to implement it, works perfectly!!!

   Thanks again
4  Using Arduino / Programming Questions / Re: converting a 0 to 000 for bluetooth transmit on: March 14, 2014, 10:39:32 am
Thanks Mark,

   I tried this:
Code:
void threedigits (byte val)
{
  onedigit (val / 100) ;
  onedigit (val / 10) ;
  onedigit (val) ;
}

void onedigit (byte val)
{
 
  int darray[3]={val % 10} ;
}
}

It compiles just fine, but when i try to pull the data out of the d array it gives me this error "'darray' was not declared in this scope"

Is it possible to pull the data out of this array somehow or do I have to do my bluetooth print from inside the array itself? 
5  Using Arduino / Programming Questions / converting a 0 to 000 for bluetooth transmit on: March 14, 2014, 06:02:42 am
I am working on a project where I would like to turn a potentiometer on one arduino, and receive the RGB information on a second through bluetooth.

   Since the PWM would work off of 0-255 integers I need to transmit the current value in 255255255 format.  The state is sent through serial and then captured and stored in an Array on the LED arduino.  So when transmitting I need to send in the full three digit count across the serial line.  If I were only using the blue led, the counts would be 0,0,255, but i need to convert the 0's to 000000255, or 10,10,255 to 010010255, etc.

6  Using Arduino / Networking, Protocols, and Devices / Re: Bluetooth to bluetooth mate loss of data on: March 11, 2014, 06:33:46 am
Hello again Paul,

    I found this old post you wrote on capturing Serial data using started && ended:  http://forums.adafruit.com/viewtopic.php?f=8&t=9918
   I was able to get the code to work using a single letter or number for control without losing data like I had been before.  I won't bother posting the code because that is not the purpose of this question.  After trying several different methods from strings to arrays I realized that as soon as I tried to capture the data and store it in an array I would lose some of the data.  I removed that part of the code and set in some delays and that is when I saw how it receives the information from the bluetooth module one piece at a time.  So at this point I realized i needed some sort of way to state this is the beginning of a string, and then have a character to declare the end of the string.  That is what led me to the post that i linked above.
   So I have taken your example and integrated it with the bare code that the bluetooth module uses, and I am getting an error compiling, I added your code one line at a time and recompiled as I went.
   Anyways I auto formatted for you :-)

Code:

#include <SoftwareSerial.h> 

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3
int inByte = 0;
char c =0;
int led = 13;
boolean started = false;
boolean ended = false;
char inData[24]; // Size as appropriate
byte index = 0;
#define SOP "{"
#define EOP "}"
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  pinMode(led, OUTPUT);
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  bluetooth.begin(115200); 
  bluetooth.print("$"); 
  bluetooth.print("$");
  bluetooth.print("$"); 
  delay(100); 
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
}

void loop(){
  while(bluetooth.available() > 0)
  {
    char inChar = bluetooth.read();
    if(inChar == SOP)
    {
      started = true;
      index = 0;
      inData[index] = '\0';
    }
    else if(inChar == EOP)
    {
      ended = true;
      break;
    }
    else
    {
      if(index < 24-1) // Array size
      {
        inData[index++] = inChar;
        inData[index] = '\0';
      }
    }
  }

  if(started && ended)
  {
    // Parse the data in inData here...
  }
}

When I try to compile this I get this error:
v1_1_ino.ino: In function 'void loop()':
v1_1_ino:35: error: ISO C++ forbids comparison between pointer and integer
v1_1_ino:41: error: ISO C++ forbids comparison between pointer and integer

It highlights this line:
    if(inChar == SOP)
7  Using Arduino / Networking, Protocols, and Devices / Re: Bluetooth to bluetooth mate loss of data on: March 10, 2014, 09:18:34 am
Hello Paul,

  I found this forum you commented on the bluetooth mate:  http://forum.arduino.cc/index.php?topic=74548.0;wap2

I noticed I don't have any delay in my loop.  When I get off work tonight ill add some delay and hopefully it might solve the problem
8  Using Arduino / Networking, Protocols, and Devices / Re: Bluetooth to bluetooth mate loss of data on: March 10, 2014, 06:48:34 am
Thanks Paul,

   I performed the Tolls Auto Format like you said and it works perfectly now!
9  Using Arduino / Programming Questions / Bluetooth to bluetooth mate loss of data on: March 10, 2014, 05:56:41 am
Hello all,

    I was able to get two bluetooth mates and two arduino pro minis communicating perfectly through the serial windows using the suggested code from sparkfun on each arduino


Code:
#include <SoftwareSerial.h> 
int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read()); 
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
 }


This worked perfectly for sending text back and forth, the next step was to be able to send commands and light a LED on the other arduino.  I found this tutorial here which i used to get the LED to light up:  http://www.instructables.com/id/Serial-Communications-with-Arduino/step4/Serial-LED-code/

I used this code to get the LED to light up, and then turn back off depending on an a or b entered into the serial window of the sending arduino

Code:

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  Serial.print ((char)bluetooth.read()); 
             inByte = (char)bluetooth.read();
             if(inByte == 'a') { // byte is 'a'
             digitalWrite(13, HIGH);
             Serial.println("LED - On");
             }
             else if( inByte == 'b'){// byte isn't 'a'
             digitalWrite(13, LOW);
             Serial.println("LED - off");
             }
                 if(Serial.available())  // If stuff was typed in the serial monitor
                  {bluetooth.print((char)Serial.read());
                  }
                }



This is working, but then instead of typing just an "a" or a "b" i decided to type in longer data to see what would happen.  I then noticed that when I type in the word hello for instance, the receiving arduino serial would only display ello, or llo, or ell.  At this point i realized that when typing just "a" or "b", sometimes the LED would not turn on or off at the first instance, sometimes i would have to enter "a" several times to get the LED to light.
    It was at this point that I realized I am loosing data somehow from the sending arduino to the receiving.  When I used the first set of code provided by sparkfun there was no data loss.  using my modified code i am getting some data loss.
   I could have my transmitting arduino always broadcast the status of the two push buttons by sending constant commands, but I would rather only transmit when a button is pushed instead of constant transmission.
    Does anyone see when my mistake is at?

Thanks
10  Using Arduino / Networking, Protocols, and Devices / Bluetooth to bluetooth mate loss of data on: March 10, 2014, 03:37:42 am
Hello all,

    I was able to get two bluetooth mates and two arduino pro minis communicating perfectly through the serial windows using the suggested code from sparkfun on each arduino
Code:

#include <SoftwareSerial.h> 
int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read()); 
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
 }

This worked perfectly for sending text back and forth, the next step was to be able to send commands and light a LED on the other arduino.  I found this tutorial here which i used to get the LED to light up:  http://www.instructables.com/id/Serial-Communications-with-Arduino/step4/Serial-LED-code/

I used this code to get the LED to light up, and then turn back off depending on an a or b entered into the serial window of the sending arduino

Code:
void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  Serial.print ((char)bluetooth.read()); 
             inByte = (char)bluetooth.read();
             if(inByte == 'a') { // byte is 'a'
             digitalWrite(13, HIGH);
             Serial.println("LED - On");
             }
             else if( inByte == 'b'){// byte isn't 'a'
             digitalWrite(13, LOW);
             Serial.println("LED - off");
             }
                 if(Serial.available())  // If stuff was typed in the serial monitor
                  {bluetooth.print((char)Serial.read());
                  }
                }

This is working, but then instead of typing just an "a" or a "b" i decided to type in longer data to see what would happen.  I then noticed that when I type in the word hello for instance, the receiving arduino serial would only display ello, or llo, or ell.  At this point i realized that when typing just "a" or "b", sometimes the LED would not turn on or off at the first instance, sometimes i would have to enter "a" several times to get the LED to light.
    It was at this point that I realized I am loosing data somehow from the sending arduino to the receiving.  When I used the first set of code provided by sparkfun there was no data loss.  using my modified code i am getting some data loss.
   I could have my transmitting arduino always broadcast the status of the two push buttons by sending constant commands, but I would rather only transmit when a button is pushed instead of constant transmission.
    Does anyone see when my mistake is at?

Thanks
11  Using Arduino / Programming Questions / Bluetooth mate serial commands on: March 09, 2014, 08:48:40 pm
I have two arduino's, and two bluetooth mates.

I have succesfully paired them and can talk back and forth through the serial terminal.

Does anyone have an example or a link to a tutorial to show how to send the status of a pushbutton or integer from one arduino and use that to control an output on the receiving through serial comms?  I am fairly new and need a good tutorial to get me going.

Thanks
12  Using Arduino / Programming Questions / Re: combine three integers into a byte, then retrieve on: March 09, 2014, 01:53:02 am
Thanks Pyro,

    That worked for the sending client, I am receiving data on the serial monitor, but it is garbled and i don't know how to unscramble it.  This is what I have:
Code:
// Should be a message for us now   
    uint8_t buf[RF22_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf22.recv(buf, &len))
    {

      a=bitRead(data,0);
      b=bitRead(data,1);
      c=bitRead(data,2);
      Serial.println("got request: ");
      Serial.print("a=");Serial.println(a);
      Serial.print("b=");Serial.println(b);
      Serial.print("c=");Serial.println(c);
      Serial.println((char*)buf);

When i run this code it print A b and c as 0, regardless of what I put in the sending radio.  There char* buf prints out =ld! or ?ld! and many others as i change the a b and c integers on the sending unit.

I tried this code to unscramble the byte back to integers.
Code:
// Should be a message for us now   
    uint8_t (data);
   
    if (rf22.recv(data)
    {

      a=bitRead(data,0);
      b=bitRead(data,1);
      c=bitRead(data,2);
      Serial.println("got request: ");
      Serial.print("a=");Serial.println(a);
      Serial.print("b=");Serial.println(b);
      Serial.print("c=");Serial.println(c);
I get these errors:
rf22_server:35: error: no matching function for call to 'RF22::recv(uint8_t&)'
/Users/wolsno2000/Documents/Arduino/libraries/RF22/RF22.h:1013: note: candidates are: boolean RF22::recv(uint8_t*, uint8_t*)

How do I take this uint8_t data and convert it back to a "byte data" so I can extract my integers from it?

Much thanks on all the help so far.

I did read the link that someone posted but it just left me more confused than i already am
13  Using Arduino / Programming Questions / Re: combine three integers into a byte, then retrieve on: March 08, 2014, 11:23:59 pm
On my client sketch I added this:
Code:
void loop()
{
    int a=0;
    int b=0;
    int c=0;
    byte data;
   
    bitWrite(data, 0, a);
    bitWrite(data, 1, b);
    bitWrite(data, 2, c);
   rf22.send(data);
   
    rf22.waitPacketSent();

I get this error:

rf22_client.ino: In function 'void loop()':
rf22_client:38: error: no matching function for call to 'RF22::send(byte&)'
C:\Program Files (x86)\Arduino\libraries\RF22/RF22.h:1021: note: candidates are: boolean RF22::send(const uint8_t*, uint8_t)

I am having a hard time grasping the pointers and uint8_t commands.
14  Using Arduino / Programming Questions / Re: combine three integers into a byte, then retrieve on: March 08, 2014, 08:27:43 pm
The integers will be the status of a digital button, so either a 1, or a 0.

The reason I have came to this is this is what was recommended to me on the rf22 forum, but they do not help with coding issues.  just issues with the radio itself.

I am open to solution, I would just like to be able to push a button on one arduino, and light an led on the receiving arduino.  that is the goal at this stage.  If I can get to that point I would be fine.
15  Using Arduino / Programming Questions / combine three integers into a byte, then retrieve on: March 08, 2014, 08:06:20 pm
 i am now working on a wireless project that calls for taking three integers, and combining them into one byte. This will be transmitted wirelessly to another arduino using rf22 radio modules, which then receives the byte, and turns that back into three integers for function control. I am basically wanting to control some lighting using relay and a wireless remote.

I have read up on pointers, and the uint8_t, and Char*. i kinda get what it is saying but it is still beyond my comprehension.

So here is what I would like to accomplish.

Code:
// this is on the Client arduino
int a = 1;
int b = 1;
int c = 1;

uint8_t data[] = "combine the three integers a,b,c here into a byte";
    rf22.send(data, sizeof(data));   //<-- does this need to be modified?




//  here is the code for the server side

    // Should be a message for us now   
    uint8_t buf[RF22_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf22.recv(buf, &len))
    {
      Serial.print("got request: ");
      Serial.println((char*)buf);
     
      // Send a reply
      uint8_t data[] = "And hello back to you";
      rf22.send(data, sizeof(data));
      rf22.waitPacketSent();
      Serial.println("Sent a reply");
    }
    else
    {
      Serial.println("recv failed");
    }
   
   // the above is the code that came with the example hello world.  I would like to take the three integers and extract them back into
// three separate bytes i can use for controlling the server functions.


Pages: [1] 2 3 ... 5