Roving Networks RN-XV + Arduino Wireless Proto Shield (rev 3)

Hi there, I was wondering with this combination, what library would I use and what modifications would I need to make in order to treat this combination like an actual wifly shield? I know the wifly shield communicates with the arduino with spi, and this module will communicate with the arduino via serial rx tx :) I am trying to use this module to replace an arduino ethernet shield (both boards are the official Arduino Shields...)...

i was hoping to use PDU and the Ardumote ipod app :) ( which currently works nicely with my ethernet shield rev 3)

if you could point me in the correct direction :) I'm pretty new to networking arduinos. :) I tried googling the topic I used here (without the (rev3)) but there were mostly just retail results :) In any case :) any help appreciated :) (building an Ardumote Treat dispenser for my pooch if all goes well )

Cheers.

It sounds like you know a lot more about networking that I do, given the acronyms you used, however, the RN-XVee will drop right into an XBee shield socket and communicate directly with the Arduino using the RX/TX pins, so I don't see that you need any libraries, per se.

XVee is very nice because you can competely forgo having to use an ethernet shield connected to some sort of wifi RF module = very expensive in total.

I have used the XVee plugged into an XBee socket in both UDP and TCP modes to communicate with ZOC telnet software on the PC end, and also wrote small UDP and TCP utilties in C# .NET, which I can embed inside my larger PC programs. Very easy.

The one problem you have with RN-XVee is in being able to get directly to the module API, in order to configure it. You either need an XBee shield/adapter that allows the XBee to directly talk to a PC, or else you "can" use an Arduino board USB port, if you cross connect the RX+TX pins, and remove or hold the Arduino in reset [short ICSP pins 5+6].

HTH.

I currently have an app on my iPhone that generates UDP messages when buttons and sliders are added (it's called Ardumote) I can create a button on the iPhone that when pressed generates the following UDP message: P2H when that code arrives on the Currently an Arduino Ethernet shield rev 3 running the following sketch:

http://samratamin.com/Ardumote_Tutorial_files/Ardumote_Example.pde

the led turns on.

because the messages are simple RDP, and the RN-XV is a serial device, I was hoping I could configure my RN-XV to listen on Port 7777 for UDP messages from 192.168.015, and then send them to the Arduino via it's serial port. Then all i need is a generic sketch that listens to the serial port for specific characters....

I expanded to sketch with additional led's and have them toggle, or stay on for a designated time... It all works great on the Ethernet Shield, but I would like this to work wirelessly ( it will be an internet based dog treat dispenser at some point... :) any additional help would be great...

cheers :)

As I mentioned, I'm sure almost everyone else knows more about general networking than I do, and maybe they'll chime in.

I've not used any of the ethernet shields, but it looks to me like your sketch specifically is made to control one, so I think it's worthless to talk to the RN-XVee module. XVee interfaces to Arudino directly via RX/TX [just like XBee] and doesn't use SPI. It's not an ethernet module.

I think you should get the XVee PDF manual and at least look at it before going too much further. It's very easy to reconfigure the module if you know how. All of the ip and wlan settings are different from in the sketch you have. You can probably write a sketch to change the settings, if you know what to do.

Tomorrow, I will get out my XVee system and take a look, but maybe someone else will get you going before then.

I made some headway with my setup... I downloaded the manual for the RN-XV, and At least for now, I have configured the RN-XV to listen on port 7777 at ip address 192.168.0.13 (my iPhone). The iPhone app Ardumote is configured with 4 buttons and a slider which generate the following UDP messages to the wifly:

Slider generates UDP message PWMXXX where xxx is the numeric value of the slider's position.

Button 1 generates a UDP message of "P7H" which will translate on the arduino (god willing and some help from my friends here...) to pin 7 High. Button 2 generates a USP message of "P7L" which will translate on the arduino to pin 7 low. Button 3 generates a UDP message of "P5P" which will translate to the arduino pin 5 on for two seconds ( Hi then a delay then low) Button 4 generates a UDP message of "OFF" which will set all three pins to low ( just incase )

so now I have to monitor the serial port ( where the messages are coming into the arduino from the rn-xv ) and try some if than statements... (not sure of the syntax yet) but something like:

if string from serial port = "P7H" set pin 7 to hi else if string from serial port = "P7L" set pin 7 to low

etc... here is the code from the ethernet shield for that part it works great I just have to figure out the serial port part... :)

/* PWM - If we move a slider on Ardumote, it sends in a 3 digit value attached to the message of the slider.

     For example, if your message is set to be "PWM" and your slider is halfway set (slider value is 127),
     then your actual sent message will be received as "PWM127".  Therefore, to set the Pin's PWM value, you simply
     extract the last 3 digits of your message and use that as your PWM value (see below):
     
  */
    
    // Assuming our packBuff's contents at index values 3-5 are our PWM values, you can convert them to an int using this:
  
     pwmVal = (packBuff[3] - '0')*100 + (packBuff[4] - '0')*10 + (packBuff[5] - '0');    //Get PWMXXX message, and use XXX to set an int between 0 and 255.

 //////////////////////// Pin 6 (LED_Pin) /////////////////////////////////////       
        
     if (packBuff[0] = 'P' && packBuff[1]=='W' && packBuff[2]=='M')  // Wait for "PWMXXX" and use XXX as value for PWM 
    {

      
      analogWrite(6,pwmVal);    //Set LED_Pin to PWM Value
      
      //Serial.println("PWM on Pin 6");    //Write notification  
    

    }

    else if (packBuff[0] = 'P' && packBuff[1]=='7' && packBuff[2]=='H')  // If we get the message "P7H", then set LED_Pin (7) HIGH
    {
      
      digitalWrite(7,HIGH);    //Turn on LED 7
  
      //Serial.println("LED 7 ON");    //Write notification 
  

    }
    
     
    
    else if (packBuff[0] = 'P' && packBuff[1]=='7' && packBuff[2]=='L')  // If we get the message "P7L", then set LED_PIN  (7) LOW
    {
      
      digitalWrite(7,LOW);    //Turn off LED 7
  
      //Serial.println("LED 7 OFF");    //Write notification 
    }   
    
   else if (packBuff[0] = 'J' && packBuff[1]=='5' && packBuff[2]=='P')  // If we get the message "J5P", then turn on Led for 2 seconds
    {
      
      digitalWrite(5,HIGH);    //Turn off LED_Pin
      delay(800);
      digitalWrite(5,LOW);
      
      //Serial.println("LED 5 Pulsed");  // write led pulsed
  
      //Serial.println("LED OFF");    //Write notification 
    }

 else if (packBuff[0] = 'O' && packBuff[1]=='F' && packBuff[2]=='F')  // If we get the message "OFF", then turn off all LEDS
    {
      
      digitalWrite(5,LOW);    //Turn off LED_Pin
      digitalWrite(6,LOW);
      digitalWrite(7,LOW);
      
      //Serial.println("All Led's Off");  // write led pulsed 
    }   
   
    
  }
  
  delay(20);
}

I have the arduino cookbook, book so I will be studying the chapter on serial communications :)

I guess I could simplify it, by having the iPhone app generate single characters for events....

so button 1 generates UDP message: x button 2 generates UDP message y button 3 generates UDP message z etc.

so there would be less to parse... the slider generates a ton of data, PWM001PWM004PWM56PWM230 etc a potentially never ending stream of data if you keep sliding our finger on the slider... so one has to keep that in mind.... if could be why the decided to do 3 character codes initially? hmmmm

any thoughts?

I made some headway with my setup... I downloaded the manual for the RN-XV, and At least for now, I have configured the RN-XV to listen on port 7777 at ip address 192.168.0.13 (my iPhone). The iPhone app Ardumote is configured with 4 buttons and a slider which generate the following UDP messages to the wifly:

I wish someone else would step in here who's more familiar with all this.

First off, how did you configure RX-XVee? From your previous msgs I don't see how you could do possibly it. ????

Secondly, it sounds like you're getting way ahead of yourself with your code. I would write a terribly simplistic program that would simply have the Arduino receive a character from XVee, and light an Led in response to a button press on your phone. This is about a 3 line program. Once that works, then you're all set and you can code complexity to your heart's content.

It's like all C coders used to write their first prpogram to print "Hello world". Getting to that point got them over a dozen initial hurdles.

It looks like you’re on the right track.

Which XBee shield are you using? Does it have an option to connect the WiFly to some digital pins other than the Arduino Tx and Rx pins? (e.g. pins 11 and 12)? If it does then you can use software serial to communicate with the WiFly, and use the hardware serial for debugging via the serial monitor. Then you can use a simple sketch like this to see what your WiFly is receiving and to send data back to it.

#include <SoftwareSerial.h>

SoftwareSerial wifly(11,12);

void setup()
{
  Serial.begin(9600);
  wifly.begin(9600);
  Serial.println("Ready");
}

void loop()
{
  if (wifly.available()) {
    Serial.write(wifly.read());
  }

  if (Serial.available()) {
    wifly.write(Serial.read());
  }
}

If your shield doesn’t have an option for different Tx and Rx pins, you might be able to convert it fairly easily by removing the D0 and D1 pins and using a couple of jumper wires to connect D0 and D1 to (for example) D11 and D12.

Once you can confirm that the UDP data is being received as expected then you can build the sketch up to receive the data and take the actions you want.

after reading the manual for the RN-XV and setting up the wireless proto shield so the rn-xv talks directly to my mac via usb ( little switch on the shield to the "usb" setting, I was able to configure the RN-XV manually by sending it commands directly...

$$$ to get it's attention, then the following:

set ip proto 1 set ip host 192.168.0.15 set ip remote 7777 set ip local 7777

save reboot

Reboot*WiFly Ver 2.31, 01-01-2012 on RN-171 MAC Addr=00:06:66:71:e7:85 Auto-Assoc Apple45 chan=11 mode=WPA2 SCAN OK Joining Apple45 now.. *READY Associated! DHCP: Start DHCP in 126ms, lease=604800s IF=UP DHCP=ON IP=192.168.0.13:7777 NM=255.255.255.0 GW=192.168.0.1

thats what I get after it reboots :)

that's pretty much it... the code quoted in the previous post was from the app website originally designed for the arduino ethernet shield... I posted it as an illustration of what I was hoping to do with the wifly wirelessly.

Howdy Mr. Dhunt, :slight_smile: I am using the “official” arduino wireless Proto Shield (with sd reader, but using that feature currently)…

it has a little switch on it so I can monitor the RN-XV Bee module directly. I would have to chop pins on it in order to change the serial port,
but what I will do instead is have the rn-xv chat with the arduino directly and set up a soft.serial port else where on the arduino and use my handy dandy spark fun FTDI to communicate with my computer to monitor the traffic using your example above :slight_smile:

I have confirmed the rn-xy is receiving the text the iPhone is sending so now I just have to parse it.

items involved:

the RN-XV: http://www.sparkfun.com/products/10822

the arduino wireless proto shield: http://arduino.cc/en/Main/ArduinoWirelessShield

on top of that I have a spark fun shield with a little breadboard on it for wiring my LED’s.

and the FTDI break out board: http://www.sparkfun.com/products/10008

these are all the players for the development side of thing… :slight_smile:

Cheers :slight_smile:

Great, it looks like you’re almost there. With your current setup, going direct to
PC, you should be able to read the data sent by the phone.

Then, just write a simple sketch for the Arduino to read the serial data, and turn
an Led on/off. Make sure the XVee and Arduino baudrates are set the same. Once
that works, add in your other tasks.

Unless you rewire the shield RX/TX pins, you cannot have the Arduino both communicate
with the PC and read the XVee at the same time, so you just have to switch the Arduino
back and forth between development (Ard Rx,Tx <->PC) and execution (Ard Rx,TX <-> XVee).

Also make sure the Arduino and Serial Monitor baudrates match.

Writing the code to monitor the serial output of the rn-xv and control leds will be the challenge...

Currently reading up on it in the arduino cookbook. Hoping to sketch something out this evening. (so to speak).

Cheers!

Writing code for the Arduino is the easy part. If not familiar, then forget about the XVee for a couple of days and learn how to write basic Arduino sketches. That's what this forum is all about. Start simple, similar to dhunt's code.

// this will write to your PC using the Serial Monitor
void setup()
{
  Serial.begin(57600);
  Serial.println("Ready");
}

// here is where you do the work, echos data-in back to PC.
void loop()
{
  if( Serial.available() ) {
    Serial.write( Serial.read() );
  }
}

Look at the simple led blink examples in Arduino IDE "File > Examples" menu. If you establish your XVee link, then the code above should communicate between your PC and the Arduino, if you use a telnet program like ZOC on the PC. Type on the keyboard and the same data should echo back. Set all the baudrates [Arduino, Serial Monitor, XVee] the same for least muckaround.

Cool thanks, here is a pick of what i have thus far:

Imgur

it’s the arduino on the bottom, then the Arduino wireless pro shield with the rn-xv mounted on it, sticking out of the right side… then a proto board with a bread board. On the breadboard, I have an FTDI connected to the soft.serial port (2,3) so I can echo what comes in the serial port to it just to make sure it’s reading the data correctly. I have a sketch from the Arduino website for setting up a soft.serial port and I did not have to do any mods to it… In the picture you will also see my iPhone with the app with the 4 buttons and a slider :slight_smile:

now I have to learn to parse the incoming data looking for key character sequences… :slight_smile:

thanks folks for your assistance… here is the sketch i am using just to monitor …

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup()  
{
  Serial.begin(9600);
 // Serial.println("Goodnight moon!"); don't really need this.... 

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?"); // this I need to make sure I am able to monitor. 
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Now I just have to do some parsing and if then’s… :slight_smile:

When you post code, can you use the [ code ] [ /code ] tags? (hit the hash button on the formatting options). This stops the forum software from messing with the formatting and presents it in a scrollable box.

As far as parsing goes, the string compare function might be helpful. It compares two strings to see if they are equal.

    if (strncmp(packBuff, "P7H", 3) == 0) {
        /* set D7 to high */
    } else if (strncmp(packBuff, "P7L", 3) == 0) {
        /* set D7 to low */
    } else if (strncmp(packBuff, "P5P", 3) == 0) {
        /* Set D5 high, record current millis() so it can be turned off 2 seconds from now */
    }

The strncmp() function, and other string functions, are described here: http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html#ga36cc0ab27fbcc70615214170ae79fbf7.

okie doke, here is my code this far… (it errors out so I know i have syntax issues…but it’s easy to see what I am trying to accomplish)
the RN-VX was already configured manually using $$$ and various commands, so i know it’s listening to UDP messages from my iPhone :slight_smile:

 /* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for P7H, P7L, P6H, P6L, P5P, and finally OFF.
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

char Buff [3]; // not sure if I need this as a character buffer?

void setup()  
{
  pinMode(5, OUTPUT); // LEDA 
  pinMode(6, OUTPUT); // LEDB
  pinMode(7, OUTPUT); // LEDC
  
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?"); // check to see if it's working
}

void loop() // run over and over
{
  while (Serial.available())  
 {
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
  
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
  
    if (strncmp(ch, "P7H", 3) == 0) //Check to see if the message is "P7H" if it is set Pin7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
      }
  
      else if (strncmp(ch, "P7L", 3) == 0) //check to see if the message is "P7L" if it is set Pin7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
    
      else if (strncmp(ch, "P6H", 3) == 0) //check to see if the message is "P6H" if it is set Pin6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
  
      else if (strncmp(ch, "P6L", 3) == 0) // check to see if the message is "P6L" if it is set Pin6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
        }
      else if (strncmp(ch, "P5P", 3) == 0) // check to see if the message is "P5P" if it is set Pin5 High for a few seconds then LOW again.
        { 
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
    
      else if (strncmp(ch, "OFF", 3) == 0) // check to see if the message is "OFF" if it is set Pin5,Pin6 and Pin7 LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
 }
}

ok I figured out the code posting bit, now I just have to figure out the syntax.

I used “char ch = Serial.read()” to read the data into “ch” ( hoping it would store the 3 characters coming in) then use the compare string function mentioned above to see if ch was one of the codes I had assigned “P7H” or “P7L” etc… but the syntax is not right… :

if (strncmp(ch, “P7H”, 3) == 0) //Check to see if the message is “P7H” if it is set Pin7. HIGH
{
digitalWrite(7,HIGH);
mySerial.println(ch); //send the message to mySerial so I can check it.
}

did not work …not sure why… I think the structure of the program is fine, now I need to work on the syntax…

P.S. I went back and properly posted the code in the code box for my posts :slight_smile:

In "char ch = Serial.read()", ch only holds a single char, so you can only do a single-character compare such as if( ch == 'P' ) ....

You can setup a character array as char datain[16], and read in data inside a while loop until there is no more data, but have to be careful you don't overflow the array. Eg,

I posted this a while back, an example sketch reading messages from the WiFly receiving UDP messages: http://arduino.cc/forum/index.php/topic,68007.msg667351.html#msg667351.

In this case the messages can vary in length so I decided to use an end of message character so the sketch knows when it has received a full message. I used 255, but it could instead be a character that you can send from the serial monitor like a '!'. The sketch builds up a string in a character array until it receives the end of message marker. Whenever it gets an end of message marker it acts on the string and resets the index for the array to start receiving the next message.

edit: fixed typo

okie doke… this did compile, I switched to single character messages… for button presses this will be fine… added a couple more buttons, loaded it to my arduino and it worked great… so this is a great wear to do some simple things with UPD an iPhone and a little help from my friends… :slight_smile: here is the code based on all the suggestions for use with single character sending.

here is a picture of it :slight_smile:

Imgur

/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for A, B, C, D, D, E, G, H and finally F for all Off
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup()  
{
  pinMode(5, OUTPUT); // LED5 
  pinMode(6, OUTPUT); // LED6
  pinMode(7, OUTPUT); // LED7
  
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?"); // check to see if it's working
}

void loop() // run over and over
{
  while (Serial.available())  
 {
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
  
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
  
    if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
      }
      
      else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
    
      else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
  
      else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
        }
      else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
        { 
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
        
        else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
        {
          digitalWrite(5,HIGH);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
    else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
        {
          digitalWrite(5,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
    
      else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
 }
}

Here is the latest code I wrote (with much help)… :slight_smile: it allows me to turn 3 devices on and off, one of them can be pulsed. it also includes control for a servo. when a button is pressed on the iPhone the servo turns 180 degrees, then back. :slight_smile: uses the servo.h and SoftwareSerial.h libraries…

/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for A, B, C, D, D, E, G, H and finally F for all Off
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup()  
{
  pinMode(5, OUTPUT); // LED5 
  pinMode(6, OUTPUT); // LED6
  pinMode(7, OUTPUT); // LED7
  
  
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?"); // check to see if it's working
  myservo.write(pos);
}



void loop() // run over and over
{
  while (Serial.available())  
 {
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
  
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
  
    if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
      }
      
      else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
    
      else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
  
      else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
        }
      else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
        { 
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
        
        else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
        {
          digitalWrite(5,HIGH);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
    else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
        {
          digitalWrite(5,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
    
      else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
        
      else if (ch == 'X') // check to see if the message is "X" if it is Dispense the treat.
        {
          myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
          for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
        {                                  // in steps of 1 degree 
          myservo.write(pos);              // tell servo to go to position in variable 'pos' 
          delay(15);                       // waits 15ms for the servo to reach the position 
        } 
          for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
        {                                
          myservo.write(pos);              // tell servo to go to position in variable 'pos' 
          delay(15);                       // waits 15ms for the servo to reach the position 
        }
        myservo.detach();
        
        }
      
        
        
        
        
 }
}