Arduino Mega

Post any hardware related questions about your WiShield 1.0 here.

Re: Arduino Mega

Postby tim » Mon Apr 12, 2010 5:19 pm

edited:
I just found out that there is a different forum for the WiShield 2.0, I posted to the new topic there
viewtopic.php?f=23&t=309

Original post:
This is what is confusing me. You say it all works fine for you. One thing I do see that might be different, my WiShield is v2.0 at least that is what is printed on the PCB.

Could you try this little sketch on your Arduino Mega with WiShield and let me know if it works for you.
It sinks the Time of the Arduino with a NIST server. It works fine on at Duemilanove and on the Arduino Mega with the interrupt remapping. But not on the Arduino Mega with the WiShield and no interrupt remap. (the remap uses interrupt 2 with is on pin 21 which is also SCL of the i2c bus)

Thanks
Tim

Not sure if the sketch is being attached or not. If not I will try again.
attaching did not work, cut and past.
#include <Time.h>
#include <TimeAlarms.h>
#include <WiShield.h>
#include <WiServer.h>

// Wireless configuration parameters
unsigned char local_ip[] = {192,168,11,6}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,11,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Bismark1"}; // max 32 bytes

unsigned char security_type = 1; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {0x83, 0x94, 0xf9, 0xa3, 0x94};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

//Set up nist time server to sync our time to
byte ip[] = {64,90,182,55};
GETrequest getDaytime(ip, 13,"nist1-ny.ustiming.org", "/");

void setup () {
Serial.begin (9600);
Serial.println ("we are in setup");
WiServer.init(NULL);
WiServer.enableVerboseMode (true);

getDaytime.setReturnFunc (syncTime2NIST);
}
int one = 1;

void loop () {
if (one) {
getDaytime.submit ();
}
one = 0;
WiServer.server_task ();
Serial.print ((timeStatus() == timeSet)?"yes":"no");
Serial.print (hour());
Serial.print (":");
Serial.print (minute());
Serial.print (":");
Serial.println (second());
Alarm.delay (1000);
}

void syncTime2NIST (char *data, int len) {
char *pointer;
byte nistTime[6];
byte n;

Serial.println ("syncTime2NIST");
if (len == 51) { //expecting 51 bytes, the rest relys on that.
pointer = &data[7];
//remove data from return string
for (n = 0; n < 6; n++) {
nistTime[n] = (byte) atoi (pointer);
pointer += 3;
}
setTime (nistTime[3], //hour
nistTime[4], //minutes
nistTime[5], //seconds
nistTime[2], //day
nistTime[1], //month
nistTime[0]); //year
adjustTime (-4*60*60); //advance UTC time to local
}
}
tim
 
Posts: 11
Joined: Sun Apr 11, 2010 1:13 pm

Re: Arduino Mega

Postby nimbusgb » Tue Apr 13, 2010 2:54 am

Will try this evening

Hmmm. No time.h
nimbusgb
 
Posts: 25
Joined: Fri Mar 26, 2010 8:13 am

Re: Arduino Mega

Postby tim » Tue Apr 13, 2010 1:02 pm

Sorry about that.

You need the Time library
http://www.arduino.cc/playground/uploads/Code/Time.zip

The code also calls Alarm.delay(1000), you could replace that with delay (1000) or download the TimeAlarm library as well:
http://code.google.com/p/arduino-time/s ... TimeAlarms
The sketch by its self does not need TimeAlarms.


Tim.
tim
 
Posts: 11
Joined: Sun Apr 11, 2010 1:13 pm

Re: Arduino Mega

Postby nimbusgb » Wed Apr 14, 2010 1:46 am

Hi Tim.

will test your code once again this evening when I get to my workbench. However .......
The V2 and v1 boards should be the same v2 adds some memory and has changed to Surface mount devices as far as I know.

Back to the interrupt problem.

When deploying the shield on the mega board the compiler apparently understands that interrupt 0 actually becomes interrupt 4 when compiling for the mega target and correctly assigns this. The problem arises in WiShield libraries file spi.h lines 47 and 48

Code: Select all
#ifdef USE_DIG0_INTR
#define ZG2100_ISR_DISABLE()      (EIMSK &= ~(0x01))
#define ZG2100_ISR_ENABLE()      (EIMSK |= 0x01)
#define ZG2100_ISR_GET(X)      (X = EIMSK)
#define ZG2100_ISR_SET(X)      (EIMSK = X)
#endif


On the Deumilove thats fine but on the mega you need to change the '0x01' entries to '0x10' Because in reality the Mega is using interrupt 4 not interrupt 0.

Perhaps what we need is something like this

Code: Select all
#ifdef USE_DIG0_INTR
#ifdef USE_MEGA
#define ZG2100_ISR_DISABLE()      (EIMSK &= ~(0x10))
#define ZG2100_ISR_ENABLE()      (EIMSK |= 0x10)
#else
#define ZG2100_ISR_DISABLE()      (EIMSK &= ~(0x01))
#define ZG2100_ISR_ENABLE()      (EIMSK |= 0x01)
#endif // using Mega board
#define ZG2100_ISR_GET(X)      (X = EIMSK)
#define ZG2100_ISR_SET(X)      (EIMSK = X)
#endif


Then you can define USE_MEGA at some point ( I've done it next to the #define USE_DIG0_INTR in my header file )
Sorry I didn't remember this in my first post.
Last edited by nimbusgb on Thu Apr 15, 2010 2:30 am, edited 1 time in total.
nimbusgb
 
Posts: 25
Joined: Fri Mar 26, 2010 8:13 am

Re: Arduino Mega

Postby tim » Wed Apr 14, 2010 12:56 pm

This seems to of done the trick.

I can now communicate on the i2c bus and over the internet via the WiShield.


Thank you very much
Tim
tim
 
Posts: 11
Joined: Sun Apr 11, 2010 1:13 pm

Re: Arduino Mega

Postby nimbusgb » Thu Apr 15, 2010 2:30 am

Excellent!
nimbusgb
 
Posts: 25
Joined: Fri Mar 26, 2010 8:13 am

Previous

Return to WiShield 1.0

Who is online

Users browsing this forum: No registered users and 1 guest