Pages: 1 2 3 [4] 5   Go Down
Author Topic: Arduino Uno + Wireless proto shield + Wifly module  (Read 14795 times)
0 Members and 1 Guest are viewing this topic.
Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post a link to the WiFly module or shield you are using?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using wifly shiled from sparkfun. Here is the link: http://www.sparkfun.com/products/9954
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used the WiFlySerial library from arduinology and the combo of the WiLFy RN-XV, Uno and Sparkfun XBee Shield and have a simple demo working. You can check it out here:
http://www.instructables.com/id/Visual-Network-Threat-Level-Indicator-v2/

I was banging my head against the wall until I saw a post about removing the diode on pin3. After that it began working.

-Joe
Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using wifly shiled from sparkfun. Here is the link: http://www.sparkfun.com/products/9954

Okay so you do have an SPI interface to the WiFly, so you're on the right track.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using this one called the RN-XV
here is the link:  http://www.sparkfun.com/products/10822

i have a thread going on a project I am working on using it.  Your thread here is very good and also helpful smiley  this is one handy little device smiley

cheers...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

Sorry i've been away from these forums lately.
Nice to read others found it usefull smiley
To update you guys: I've been cracking away on a simple script where i can (once connected through telnet) send a string and let the arduino process it, ie:
00; //turn led off
01; //turn led on
02;<column>;<row>;string //post the string on my lcd on the correct position..
03; // read value from a LDR and map it's value from 0 - 100 %, update the LCD with this value, as well as write the value to Serial.

I have the WiFly configured through serial, so no need to configure the WLAN stuff in the sketch, which is nice.

The sketch is working, well sorta.. It has a few bugs in it.
Would you guys be interested in the sketch just to check it out, or maybe even help fix the bugs? (warning, i'm still a newb in c.. smiley-razz)
If there is interest in it, i will post it tonight when i get home.
Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Of course, post away!
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I re-wrote the sketch again and it seems this one works without bugs!  smiley
The getBuffer function i found somewhere on the web, but i don't remember where, so credits go to anonymous  smiley-zipper
Any hints or comments on how to improve on this code / my coding are greatly appreciated!

Code:
#include <LiquidCrystal.h>

   LiquidCrystal lcd ( 12, 11, 5, 4, 3, 2 );
   int led = 13;
   int ldr = 0;
   int ldrValue = 0;
   int ldrPercentage = 0;
   char buffer[30];
   int bufferSize;
   
   void setup()
   {
      pinMode(led, OUTPUT);
      pinMode(ldr, INPUT);
      Serial.begin(9600);
      lcd.begin( 20, 2);
   }
   
   void GetLdr()
   {
      ldrValue = analogRead(ldr);
      ldrPercentage = map(ldrValue, 0, 1023, 0, 100);
   }
   
   void UpdateLcd(String msg, int col, int row)
   {
      lcd.setCursor( col, row );
      lcd.print(msg);
   }
   
   void GetIp()
   {
      //WiFly wants 250 ms minimum before and after the $$$ when entering command mode
      delay(300);
      Serial.write("$$$");
      delay(300);
      Serial.println("get ip a");

      Serial.print("exit");
      Serial.println("\n");
      GetBuffer("\0");
      Serial.write(buffer);
     
   }
   
   char GetBuffer(char* This)
   {
      int index = 0;
      while(Serial.available() > 0)
      {
         delay(2);
         buffer[index] = Serial.read();
         index++;
         buffer[index] = '\n';
         bufferSize = index;
      }
         
         if(strcmp(buffer, This) == 0)
         {
            for(int i=0;i<30;i++)
            {
               buffer[i] = 0;
            }
            index = 0;
            return(0);
         }else{
            return(1);
         }
   }
   
   void ParseBuffer()
   {
      char cCmd[3] = {buffer[0], buffer[1], '\0'};
      int cmd = atoi(cCmd);
      switch(cmd)
      {
         case 0:
         {
           //turn led off:
           digitalWrite(led, LOW);
           Serial.write("led is OFF!");
         }
         break;
         case 1:
         {
            //turn led on:
            digitalWrite(led, HIGH);
            Serial.write("led is ON!");           
         }
         break;
         case 2:
         {
            GetIp();
         }
         break;
      }
   }
   
   void loop()
   {
      delay(2);
      if(Serial.available() > 0)
      {
         GetBuffer("\0");
         ParseBuffer();
      }else{
         GetLdr();
         lcd.print("LDR Value: ");
         lcd.setCursor(0,1);
         lcd.print(ldrValue);
         lcd.setCursor(0,0);
         delay(200);
      }
   }
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Heey sponder,

Are you able to get the desired output i.e turning on and off LED and writing on the LCD from this code?. Am asking this because I realized you are using Serial instead of spiSerial.

Also how do you clear the LCD every time you receive data from the wifly? I tried to put lcd.clear() after spiserial.available() statement but only the first letter of the newly received message is displayed.

Thanks.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to make the second point above clear, what I meant is that when I first send a message to the LCD it gets printed out correctly but when I send a another but of shorter length then this message plus the last few characters of the previous message are printed out. For example I send "Helooo"  then I send "Hey" I get this on the LCD "Heyooo" meaning that the previous message wasnt cleared before printing the new message.

I tried to put lcd.clear() but only the first characters of the messages sent are displayed. Below is my code.

Code:

#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.
#include <LCD4Bit_mod.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);

  
void setup() {
  lcd.init();
  lcd.clear();
  lcd.cursorTo(1, 0);
  SpiSerial.begin();
  
}

void loop() {
  lcd.cursorTo(1, 0);
  // Terminal routine
  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  while(SpiSerial.available() > 0) {
    // lcd.clear();
     lcd.print(SpiSerial.read());
 }
}


I want to clear the LCD on every TCP connection so that the new message will be clearly displayed.
« Last Edit: March 10, 2012, 02:07:00 am by mc63 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Yes, the code is working. (i will update the current code here tonight)
if i send a 1 it will read a LDR and map it's value to turn the led on with the intensity relative to the read out on the LDR. i can also send a value (01;255 for max) with it and control it manually. I used this to control the backlight of my LCD.

for your problem,  you know that the lcd.clear is commented out right?
Also, i would try to seperate the clear from the print ie:
Code:
void loop() {
  lcd.cursorTo(1, 0);
  // Terminal routine
  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
   if(SpiSerial.available > 0)
   {
      lcd.clear();
   }
  while(SpiSerial.available() > 0) {
     lcd.print(SpiSerial.read());
 }
Otherwise (at least that's what my noob-instincts tell me, someone correct me if i'm wrong..) you have a while loop where you say:
clear - print - clear - print - clear - print for as long as you have data available.
But you only want to clear the screen once right? ie:
clear - print - print - print for as long as there is data available. Once a new message comes in the buffer, you want to repeat it..
I'm not familiair with the LCD4Bit_mod library, are you sure that the method clear clears the whole screen? (or just one char on the current position?)

Let me know how it works out!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Sponder, I tried out your suggestion but getting same result. I commented out the lcd.clear in my code intentionally because it was clearing the message that is received because of the looping. I got an idea on how to solve this but I luck the tech-no-how. I think what I have to do is to reset the arduino uno automatically every time it receives new message so that the lcd will be cleared properly. Is this ok?..if so how to go about it?..

Thanks.
Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It might be a timing problem.  The serial data comes to the Arduino quite slowly, so allowing some time for that might help:

Code:
uint32_t lastRead = 0;

void loop() {
  lcd.cursorTo(1, 0);
  // Terminal routine
  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  if (SpiSerial.available() > 0) {
      lcd.clear();
      lastRead = millis();
  }
  while ((millis() - lastRead) < 50) {
      if (SpiSerial.available() > 0) {
          lcd.print(SpiSerial.read());
          lastRead = millis();
      }
  }
}

This will keep reading in bytes and displaying them as long as they are received within 50 milliseconds of each other.  Then anything later than 50 milliseconds will clear the lcd and start printing again. That might be too long; it depends on how fast you are running the serial interface to the WiFly module and how much time there is between packets.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks dhunt. I will give your suggestion a try once i get home. What do you say about resetting the arduino uno every time data is received by the wifly shield?.

Thanks.
Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks dhunt. I will give your suggestion a try once i get home. What do you say about resetting the arduino uno every time data is received by the wifly shield?.

Thanks.

I think that to get the LCD to reset you would need a power reset, which you can't do from software.  Or maybe there's a reset line from your LCD connected to the Arduino? If so you can reset it using that, or send a reset command to it via the lcd library.  Seems a bit of overkill when you can just clear the lcd.
Logged


Pages: 1 2 3 [4] 5   Go Up
Jump to: