Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / Re: Check WiFi link status before sending request ? on: June 30, 2013, 04:13:45 pm
WiFi.status() doesn't seem useful. It appears to return 3 as long as I've had a successful connection.

It shows a result of 3 both when link LED is red and when it's green.
2  Using Arduino / Networking, Protocols, and Devices / Re: Check WiFi link status before sending request ? on: June 30, 2013, 09:12:38 am
The Arduino is acting as a client.

I've looked at the documentation at http://arduino.cc/en/Reference/WiFi and I see no status method listed there. Where can I find documentation on that ?
3  Using Arduino / Networking, Protocols, and Devices / Check WiFi link status before sending request ? on: June 30, 2013, 06:37:03 am
Hi all,

How do I check my WiFi link status before sending a network request? The only way I can see to check my WiFi status is by using the WiFi.begin() (http://arduino.cc/en/Reference/WiFiBegin) method.

What I'm seeing is that if my Arduino boots up and connects to the network, then has no activity for a long period of time, it loses the connection to the network. If this happens, the next action I take seems to reconnect it, but that request fails.

The symptoms I see on the board are as follows:
 - Link light is green
 - Push button to trigger network traffic
 - Link light goes red
 - Request fails
 - Link light goes green
 - Push button to generate network traffic
 - Request succeeds

I'd like to check the link status on each button press to ensure that I have a valid link _before_ sending the request, and then attempt to re-establish the link if it's not valid.

Thanks,

4  Using Arduino / Installation & Troubleshooting / Re: Any way to update optiboot without having a second arduino ? on: February 13, 2013, 02:22:30 am
Thanks for the replies all.

The programmer working only on Windows is an issue for me - my environment is Linux and Mac. I can run Windows in a VM, but I've seen issues with hardware not working properly through VMWare before.

I'll look for a 328P chip and get that burned.
5  Using Arduino / Installation & Troubleshooting / Any way to update optiboot without having a second arduino ? on: February 12, 2013, 04:10:58 pm
Hi all,

It looks like I've run into the problem described at http://code.google.com/p/arduino/issues/detail?id=380 where I can't upload sketches larger than 28,992 bytes.

A solution at http://forums.adafruit.com/viewtopic.php?f=31&t=19243#p100082 describes a way to patch my existing Uno rev 1 using a second Arduino. I don't have one or know anyone who has one that I could borrow though.

Is there any way to do this without a second Arduino ?

Failing that, can this fix be done from a Mega? If I have to buy a new one to fix this problem, I figure I may as well get something with more memory.
6  Using Arduino / Programming Questions / Re: How to use SD and WiFi at the same time ? on: February 12, 2013, 01:21:48 pm
Maybe running out of SRAM? Try using the F() function to keep the static strings in program memory like this.
Code:
  Serial.println(F("Arduino in setup()"));
Do the rest to all the other static strings. See if that helps.


That seems to have done the trick - I wasn't aware that my use of static strings like this could hurt me in the long run. I've now added this to all of them. Now to just look up the F function and see what cost this magic comes at smiley

Thanks loads for your help!
7  Using Arduino / Programming Questions / Re: How to use SD and WiFi at the same time ? on: February 12, 2013, 01:06:49 pm
Fails how? Doesn't print the mac? Doesn't connect? What is the last thing displayed before the fail?


After uploading the sketch, all I get is
Code:
Arduino in

If I then press the reset button on the arduino, I then see
Code:
IĀŠArduino in 
Arduino in 
8  Using Arduino / Programming Questions / Re: How to use SD and WiFi at the same time ? on: February 12, 2013, 12:42:24 pm
If that works ok, then copy and paste your wifi startup where I put the comment. Then it should start the wifi ok. The SD library begin() function call returns with the SD SPI disabled (D4 HIGH).

edit. Once these SS lines are initialized, you do not need to manipulate them anywhere else. The libraries will take care of that in the low level read/write functions.


Huh, ok - thanks!

Interestingly it works if I have the SD and the WiFi setup all in the setup() method. If I do the SD and then do the WiFi in a separate method (like I had it with connectToNetwork, then it fails still.

Any idea why that is ?

Again - thanks for the help - it makes the setup a bit more ugly, but it lets me keep going smiley
9  Using Arduino / Programming Questions / Re: How to use SD and WiFi at the same time ? on: February 12, 2013, 12:27:06 pm
Both use the SPI bus. Disable the wifi SPI before starting the SD.

Does that setup work?


That setup then completes the SD init, but fails to progress on the WiFi init.

Do I then have to disable the SD SPI before trying to start the WiFi? And do I have to keep swapping that each time I wish to use one or the other ?
10  Using Arduino / Programming Questions / How to use SD and WiFi at the same time ? on: February 12, 2013, 12:12:47 pm
Hi all,

I have a WiFi shield on an Arduino Uno (rev 1), and I'm trying to use the wifi and the SD card in the same sketch. I can use the SD card in its own sketch, and I can use the the WiFi in a separate sketch. But as soon as I try and use them in the same sketch, things behave oddly.

Can anyone point me at an example that uses both the WiFi shield and the SD card in the same sketch, or advise where I'm going wrong here please?

The only change between working and failing is the addition of the following lines to the setup() method

Code:
  pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


Working example code
Code:
#include <SPI.h>
#include <WiFi.h>
#include <SD.h>
#include <LiquidCrystal595.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal595 lcd(5,6,8);

// Wifi network details
char ssid[] = "MySSID";     //  your network SSID (name)
char pass[] = "passwordtomynetwork";    // your network password
int wifiStatus = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;
boolean lastConnected = false;

/* setup
   Setup various pin modes, LCD display and ensure that we are connected to the wifi network
*/
void setup() {
  Serial.begin(9600);

  Serial.println("Arduino in setup()");
 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.print("Temp: ");
 
  wifiStatus = connectToNetwork();
}

/* connectToNetwork
   Connect to a wifi network
   
   - if we are able to connect to the network, we briefly display the SSID on the LCD then Net: OK
   - if we fail to connect to the network, we display Net: BAD on the LCD
*/
int connectToNetwork() {
  while(!Serial) ;
 
  Serial.println("Initializing Wifi...");
  printMacAddress();
 
  Serial.print("Attempting to connect to WPA network: [");
  Serial.print(ssid);
  Serial.println("]");
  lcd.setCursor(0, 1);
  lcd.print("Connecting...");
  wifiStatus = WiFi.begin(ssid, pass);
 
   // if you're not connected, stop here:
  if ( wifiStatus != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    lcd.setCursor(0, 1);
    lcd.print("Net: BAD       ");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    lcd.setCursor(0, 1);
    String ssidString = ssid;
    int padCount = 16 - ssidString.length();
    if (padCount > 0) {
      for (int i = 0; i < padCount; i++) {
        ssidString + ssidString + " ";       
      }
    }
    lcd.print(ssidString);
    delay(2000);  // Change this value to define how long the SSID is displayed on the LCD before we proceed
   
    lcd.setCursor(0,1);   
    lcd.print("NET: OK          ");
  }
  return wifiStatus;
}

/* printMacAddress
   Finds the WiFi shield's mac address and prints it to the serial output. This is used for debugging
*/
void printMacAddress() {
  // the MAC address of your Wifi shield
  byte mac[6];                   

  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
}

Working example output
Code:
Arduino in setup()
Initializing Wifi...
MAC: 7A:C4:E:94:EA:2A
Attempting to connect to WPA network: [MySSID]
Connected to network


Failure example code
Code:
#include <SPI.h>
#include <WiFi.h>
#include <SD.h>
#include <LiquidCrystal595.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal595 lcd(5,6,8);

// Wifi network details
char ssid[] = "MySSID";     //  your network SSID (name)
char pass[] = "passwordtomynetwork";    // your network password
int wifiStatus = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;
boolean lastConnected = false;

/* setup
   Setup various pin modes, LCD display and ensure that we are connected to the wifi network
*/
void setup() {
  Serial.begin(9600);

  Serial.println("Arduino in setup()");
 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.print("Temp: ");

  pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  wifiStatus = connectToNetwork();
}

/* connectToNetwork
   Connect to a wifi network
   
   - if we are able to connect to the network, we briefly display the SSID on the LCD then Net: OK
   - if we fail to connect to the network, we display Net: BAD on the LCD
*/
int connectToNetwork() {
  while(!Serial) ;
 
  Serial.println("Initializing Wifi...");
  printMacAddress();
 
  Serial.print("Attempting to connect to WPA network: [");
  Serial.print(ssid);
  Serial.println("]");
  lcd.setCursor(0, 1);
  lcd.print("Connecting...");
  wifiStatus = WiFi.begin(ssid, pass);
 
   // if you're not connected, stop here:
  if ( wifiStatus != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    lcd.setCursor(0, 1);
    lcd.print("Net: BAD       ");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    lcd.setCursor(0, 1);
    String ssidString = ssid;
    int padCount = 16 - ssidString.length();
    if (padCount > 0) {
      for (int i = 0; i < padCount; i++) {
        ssidString + ssidString + " ";       
      }
    }
    lcd.print(ssidString);
    delay(2000);  // Change this value to define how long the SSID is displayed on the LCD before we proceed
   
    lcd.setCursor(0,1);   
    lcd.print("NET: OK          ");
  }
  return wifiStatus;
}

/* printMacAddress
   Finds the WiFi shield's mac address and prints it to the serial output. This is used for debugging
*/
void printMacAddress() {
  // the MAC address of your Wifi shield
  byte mac[6];                   

  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
}

Failure example output
Code:
Arduino in setup()
inMAC:
11  Using Arduino / Project Guidance / Re: Difference between pins 2 and 11 ? on: January 19, 2013, 02:37:07 pm
Thanks - I'll give that a try tomorrow for sure !
12  Using Arduino / Project Guidance / Re: Difference between pins 2 and 11 ? on: January 19, 2013, 06:57:13 am
Quote
Do remember that analog pins can be used as digital if you don't need them for analog

I wasn't aware of that - thanks for the pointer. I'll google on how to use those as digital. I only need 3 analog pins for this project for sensor input, so that should give me a few more options.

I just thought that analog pins were analog and that was that smiley
13  Using Arduino / Project Guidance / Re: Difference between pins 2 and 11 ? on: January 19, 2013, 06:04:45 am
Quote
What LCD are you using?

If it's something like a 16x2 or 2x40 character based display then there are ways of reducing the number of pins required by using IO expansion, in the form of Shift Registers or I2C expanders.

It's a 16x2 - http://www.oomlout.co.uk/lcd-display-16-x-2-p-212.html. I've got a 74HC595 shift register that came with my starter kit - I didn't know that there was an option to reduce the pin use.

I'm using the LiquidCrystal library at the moment, so this sounds quite feasible.

Do you know of any tutorials on this or links that give a brief explanation of the electronics side ?

Thanks!
14  Using Arduino / Project Guidance / Re: Difference between pins 2 and 11 ? on: January 19, 2013, 03:44:09 am
An, yes - I should have mentioned it's an Uno.

So using a wifi shield really reduces the number of remaining inputs then - I didn't realise that. I'll have to remove the LCD from the project if I still want to use switches.

Thanks for the response.
15  Using Arduino / Project Guidance / Difference between pins 2 and 11 ? on: January 18, 2013, 06:48:40 pm
All,

I've got a project that includes a WiFi shield, an LCD and a button.

When I wire my switch to pin 2, it works as expected - while the switch is pressed, the state is LOW and actions can happen in the loop. When I wire my switch to pin 11 or 12 (and change buttonPin to 11 or 12 in the sketch), when I press it, the state then stays LOW forever, even when I release it.

I am currently using pin 2 for Data 7 on the LCD and I can't work out why they behave differently.

Also, with the wifi shield, can I still use pins 11, 12 and 13 as input / output pins ? Or does the shield need them like it does 10 and 7 ?

Thanks,
Pages: [1] 2