-
You Reply: No it is not compatible with the Ethernet library as the WiFi shield only uses RX and TX on the Arduino (data pins D0 and D1) while the Ethernet Shield uses D10,D11,D12 and D13 to send and receive data.
I too have a WiFi Shield and am having problems with writing sketches for it........
PLEASE MR DFROBOT give us beginners a library or a sample sketch for TCPIP and UDP so we can see how to make it work
-
You Reply: I believe the schematic does not match the board.
The 3.3v regulator in the schematic is attached to the 5v line but on my (two) boards they are attached to the VIN line.
That means the WiFi board does not take its power from the 5v line. Not an issue if it is powered by a battery or whatever BUT the 5v pin J4 pin3 is not connected to the J4E pin 3 so any shields plugged in on top of the WiFi shield will not receive power from the 5v line. Get an ohm meter and test it, it may be the problem why your LCD did not work.
-
You Reply: I believe the schematic does not match the board.
The 3.3v regulator in the schematic is attached to the 5v line but on my (two) boards they are attached to the VIN line.
That means the WiFi board does not take its power from the 5v line. Not an issue if it is powered by a battery or whatever BUT the 5v pin J4 pin3 is not connected to the J4E pin 3 so any shields plugged in on top of the WiFi shield will not receive power from the 5v line. Get an ohm meter and test it, it may be the problem why your LCD did not work.
-
You Reply: Hi
I am trying to do the same sort of thing as you but I have started by using a Mac sketch written in "Processing", which is very similar to the Arduino, to send UDP packets to the Arduino with the DFRobot Ethernet Shield which will then turn LEDs on and off and reply (using UDP) back to the Mac.
So far it all works fine but I then bought a WiFi shield from DFRobot and found that it is SOOOOO different to the Ethernet shield. Then I started hunting forums to find out why - and I still have no idea.
I have only been writing in C++ and the Arduino for about a month so I am no expert by a very long way.
Looking at your code I think your case statement fails because the char data type if inByte is only a byte in size and you are looking at strings not chars.
Here is all my code - it's a bit long !!
//This sketch receives UDP message strings, prints them to the 4x16 LDC Screen
//and sends an acknowledge string back to the sender
//it also updates the leds on 2 x daisy chained 74HC595 (serial to paralel chip with tristate & latch)
#include <LiquidCrystal.h>
#include <Ethernet.h>
#include <Udp.h> // UDP library from: [email protected] 12/30/2008
#include <SPI.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // DFROBOT LCD Pin Assignment
int latchPin = 17; //Pin connected to ST_CP of 74HC595
int clockPin = 18; //Pin connected to SH_CP of 74HC595
int dataPin = 16; //Pin connected to DS of 74HC595
byte Hundreds; //used to extract Hundreds from a byte
byte Tens; //used to extract Tens from a byte
byte Units; //used to extract Units from a byte
byte dataLO; //Low order byte containing bits
byte dataHI; //High order byte containing bits
byte dataWorkLO; //used to calculate bit position to set in LO Byte
byte dataWorkHI; //used to calculate bit position to set in HI Byte
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x33, 0xAB }; // MAC address of shield but Im not sure why
byte ip[] = { 192,168,2,177 }; // IP address of shield
unsigned int localPort = 8888; // local port to listen on
// next variables set when a packet is received
byte remoteIp[4]; // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "UDP - Ack"; //Reply string in an array of that length **
void setup() {
pinMode(latchPin, OUTPUT); //set latch pin to output
Ethernet.begin(mac,ip); // start Ethernet
Udp.begin(localPort); // start UDP
Serial.begin(9600); // start Serial
lcd.begin(16, 4); // start LCD
lcd.setCursor(0,0); // set cursor to pos 1 line 1
lcd.print("UDP Demo Program"); // print a simple message
lcd.setCursor(0,1); // This is all printed on a 4 line x 16ch LCD
lcd.print("90-A2-DA-00-33-AB");
lcd.setCursor(-4,2);
lcd.print("192.168.2.177");
lcd.setCursor(-4,3);
lcd.print("UDP Port 8888");
delay(5000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Waiting for UDP");
lcd.setCursor(1,2);
lcd.print("Packet");
dataLO = 0;
dataHI = 0;
}
void loop() {
int packetSize = Udp.available(); // note that this includes the UDP header
if(packetSize) // if there's data available, read a packet
{
packetSize = packetSize - 8; // subtract the 8 byte header
lcd.clear(); // clears LDC and moves Cursor to Pos 1 line 1
lcd.print("Packet Size:");
lcd.print(packetSize); //Number of bytes in the UDP Packet
// read packet into packetBufffer - senders IP and port no
Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
lcd.setCursor(0,1); // move Cursor to Pos 1 line 2
// lcd.print("Data:");
lcd.print(packetBuffer);
lcd.setCursor(-4,2); //move Cursor to Pos 1 line 3
lcd.print(remoteIp[0],DEC); //IP address byte displayed as decimal
lcd.print('.');
lcd.print(remoteIp[1],DEC); //IP address byte displayed as decimal
lcd.print('.');
lcd.print(remoteIp[2],DEC); //IP address byte displayed as decimal
lcd.print('.');
lcd.print(remoteIp[3],DEC); //IP address byte displayed as decimal
lcd.setCursor(-4,3); //move Cursor to Pos 1 line 4
lcd.print("Remote Port:");
lcd.print(remotePort,DEC); //Remote Port byte displayed as decimal
// Start filling the dataHi or dataLO acording to the packetBuffer contents dataHI & dataLO
if (packetBuffer[0] == 'H' || packetBuffer[0] == 'L') { //UDP Data Packet starts with H or L then 1-8 then 1 or 0
if (packetBuffer[0] == 'H') {
dataWorkHI = (1<<packetBuffer[1]-49); //Takes the 2nd Char and raises 2 to the power of 2nd
dataWorkLO = 0;
}
else {
dataWorkLO = (1<<packetBuffer[1]-49); //Takes the 2nd Char and raises 2 to the power of 2nd
dataWorkHI = 0;
}
if( packetBuffer[2] == '1') { //turn on pin with a bitwise OR
dataHI = dataHI | dataWorkHI;
dataLO = dataLO | dataWorkLO;
}
else { //turn off a pin Bitwise & to test for already on and the bitwise xor
dataHI = (dataHI & dataWorkHI) ^ dataWorkHI;
dataLO = (dataLO & dataWorkLO) ^ dataWorkLO;
}
}
if (packetBuffer[0] == 'A') { //UDP Date Packet starts with AL then 1 or 0
if( packetBuffer[2] == '1') { //turn on all pins
dataHI = 255;
dataLO = 255;
}
else { //Turn off all pins
dataHI = 0;
dataLO = 0;
}
}
if (packetBuffer[0] =='H' || packetBuffer[0] == 'L' || packetBuffer[0] == 'A') {
if (packetSize = 3) {
ReplyBuffer[0] = packetBuffer[0]; //Fill the ReplyBuffer with the sent data + Ack
ReplyBuffer[1] = packetBuffer[1];
ReplyBuffer[2] = packetBuffer[2];
ReplyBuffer[3] = ' ';
ReplyBuffer[4] = '-';
ReplyBuffer[5] = ' ';
ReplyBuffer[6] = 'A';
ReplyBuffer[7] = 'c';
ReplyBuffer[8] = 'k';
}
else {
ReplyBuffer[0] = 'B'; //Short data received so bad reply sent back
ReplyBuffer[1] = 'A';
ReplyBuffer[2] = 'D';
ReplyBuffer[3] = ' ';
ReplyBuffer[4] = '-';
ReplyBuffer[5] = ' ';
ReplyBuffer[6] = 'U';
ReplyBuffer[7] = 'D';
ReplyBuffer[8] = 'P';
}
}
if (packetBuffer[0] == 'S') { //Pin Status sent back to sender STA
Hundreds = 0;
Tens = 0;
Units = 0;
if (dataHI > 99) {
Hundreds = (dataHI/100);
}
if (dataHI-(Hundreds * 100) > 9) {
Tens = ((dataHI-(Hundreds*100))/10);
}
Units = (dataHI-(Hundreds*100)-(Tens*10));
Hundreds = Hundreds + 48;
Tens = Tens + 48;
Units = Units + 48;
ReplyBuffer[0] = 'H';
ReplyBuffer[1] = Hundreds;
ReplyBuffer[2] = Tens;
ReplyBuffer[3] = Units;
ReplyBuffer[4] = '-';
Hundreds = 0;
Tens = 0;
Units = 0;
if (dataLO > 99) {
Hundreds = (dataLO/100);
}
if (dataLO-(Hundreds * 100) > 9) {
Tens = ((dataLO-(Hundreds*100))/10);
}
Units = (dataLO-(Hundreds*100)-(Tens*10));
Hundreds = Hundreds + 48;
Tens = Tens + 48;
Units = Units + 48;
ReplyBuffer[5] = 'L';
ReplyBuffer[6] = Hundreds;
ReplyBuffer[7] = Tens;
ReplyBuffer[8] = Units;
}
remotePort = 6000; // forced return port
remoteIp[0] = 192; // forced return IP Address
remoteIp[1] = 168; // forced return IP Address
remoteIp[2] = 2; // forced return IP Address
remoteIp[3] = 211; // forced return IP Address
Udp.sendPacket( ReplyBuffer, remoteIp, remotePort);
// end of filling the dataHI and dataLO
digitalWrite(latchPin, 0); //ground latchPin during transmitting
shiftOut(dataPin, clockPin, dataHI); //move Upper byte first
shiftOut(dataPin, clockPin, dataLO); //move out lower byte
digitalWrite(latchPin, 1); //return the latch pin high to Latch the data out
lcd.setCursor(-4,2); //move Cursor to Pos 1 line 3 because my 4 line LCD is a bit odd
lcd.print(" ");
lcd.setCursor(-4,2); //move Cursor to Pos 1 line 3 because my 4 line LCD is a bit odd
lcd.print(dataHI,BIN); //HI Byte as bits
lcd.setCursor(-4,3); //move Cursor to Pos 1 line 4 because my 4 line LCD is a bit odd
lcd.print(" ");
lcd.setCursor(-4,3);
lcd.print(dataLO,BIN); //LO Byte as bits
}
delay(10);
}
// This function shifts 8 bits out MSB first, on the rising edge of the clock, clock idles low
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0; //internal function setup
int pinState; //internal function setup
pinMode(myClockPin, OUTPUT); //setup Clock pin as digital output
pinMode(myDataPin, OUTPUT); //setup Data pin as digital output
digitalWrite(myDataPin, 0); //serial data pin low
digitalWrite(myClockPin, 0); //clock pin low
//for each bit in the byte myDataOut in our for loop
for (i=7; i>=0; i--) { //loop 8 times for the 8 bits from 7 to 0
digitalWrite(myClockPin, 0); //Set clock pin low
if ( myDataOut & (1<<i) ) { //Test the i bit AND - Bit Shift left by "i" places
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState); //Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myClockPin, 1); //register shifts bits on upstroke of clock pin
digitalWrite(myDataPin, 0); //zero the data pin after shift to prevent bleed through
}
digitalWrite(myClockPin, 0); //stop shifting
}
If you have a full list of your WiFi sketch and how you have set up the WiFi shield that would be good to see and try and understand