This time I was to check the compact version of arduino without the need of any additional FTDI cable to connect. This board hasn't any led connected to Pin13 like UNO, so will use the onboard led for RX and TX indication. Actually RX led is connected to Pin17 (internal pin), but in our example will use predefined macros RXLED() and TXLED(). These macros are not compatible with the UNO board but the UNO has already onboard led on Pin13.
Test sketch:
// Blink test with RX-TX leds of Leonardo micro void setup() { // nothing need to be setup :) }
void loop() { RXLED1; //RX led set to ON TXLED0; //TX led set to OFF delay(1000);// wait for a second RXLED0; //RX led set to OFF TXLED1; //TX led set to OFF delay(1000);// wait for a second }
today I work with my ENC28J60 module, a cheap alternative to the standard W5100 Ethernet shield. If you want to use with the 1.0.5+ IDE then the EtherCard library is one way. after many research I found the best articles here (http://www.lucadentella.it/en/category/enc28j60-arduino)
My final scope is to remotely control some relays and read sensors thru web interface. Finally I manage to write a sketch, but I want to read/learn more in order to make html page code better and of course to add security in order to not anybody open/close my relays ...
This is the sketch till now:
/************************************************** Remotelly read sensor data and control relays without any security... yet ;-) arduino UNO, ENC28J60, DT11 and two relays module DT11 3 cables: A0 analog pin, VCC +5V, GND ENC28J60 6 cables: SI ->D11, SO ->D12, SCK ->D13, CS ->D8, VCC ->3v3, GND Relays Module 4 cable: IN1 ->D2, IN2 ->D3, VCC +5v, GND This is sketch based to infos collected from varius sites but the most valuable was the pages found on http://www.lucadentella.it/en/category/enc28j60-arduino/ many many many thanks for it's hard and good work!!! the ENC28J60 solution is very cheap but it lacks in support, especially for EtherCard.h library which is the only one to make small and quick sketches working with IDE 1.0.5+ I am not experience in programming so excuse any mistakes that I make... any comments are welcome in my blog http://demerduino.blogspot.gr/ sketch ver.1401.14 *******************************************************/ // declare libraries and variables #include <EtherCard.h> #include <dht.h> #define dht_dpin A0 #define REL1PIN 2 #define REL2PIN 3 static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01}; static byte myip[] = {192,168,1,2}; byte Ethernet::buffer[500]; boolean rel1Status; boolean rel2Status; unsigned long timer; float temp; float hum; char temp_str[10]; char hum_str[10]; dht DHT; void setup () { Serial.begin(9600); // small delay for sensor delay(500); // initialize lan CS pin on digital pin 8 if (!ether.begin(sizeof Ethernet::buffer, mymac, 8)) Serial.println( "Failed to access Ethernet controller"); else Serial.println("Ethernet controller initialized"); if (!ether.staticSetup(myip)) Serial.println("Failed to set IP address"); // define relays pins pinMode(REL1PIN, OUTPUT); pinMode(REL2PIN, OUTPUT); // in my board the 'LOW' (false) state put relays ON so I start with 'HIGH' // if you want to change this change also the states OFF-ON later on the sketch rel1Status = true; rel2Status = true; } void loop() { // applying the status on pins (relays) digitalWrite(REL1PIN, rel1Status); digitalWrite(REL2PIN, rel2Status); // This is the "heart" of the DT11 program, the proposal sample rate // is 1/sec after the variables fill the string variables if (millis() > timer) { timer = millis() + 1000; DHT.read11(dht_dpin); temp= DHT.temperature; hum = DHT.humidity; dtostrf(temp,6,2,temp_str); dtostrf(hum,6,2,hum_str); } // check for ethernet and tcp packet word len = ether.packetReceive(); word pos = ether.packetLoop(len); // read the parameter and change the status of relay's pin if(pos) { if(strstr((char *)Ethernet::buffer + pos, "GET /?REL1") != 0) { rel1Status = !rel1Status; } else if(strstr((char *)Ethernet::buffer + pos, "GET /?REL2") != 0) { rel2Status = !rel2Status; } // bulding the html file... // the two $S are filled with string variables BufferFiller bfill = ether.tcpOffset(); bfill.emit_p(PSTR( "HTTP/1.0 200 OK\r\n" "Content-Type: text/html\r\n" "Pragma: no-cache\r\n\r\n" // if you want to enable the auto refresh mode // "<meta http-equiv='refresh' content='5'/>" "<html><head><title>Web Control</title></head><body>" "<body bgcolor=""#ccccff"">" "<font size=""6"">" "<center><br>" "Temperature... : " "<b> $S °C </b> <br>" "Humidity... : " "<b> $S %</b><br>" "____________________<br>" "<BR>"), temp_str,hum_str); // and now the relays status / hyperlinks if(rel1Status) bfill.emit_p(PSTR("Relay No_1 is <a href=\"/?REL1\">$F</a><br>"),PSTR("OFF")); else bfill.emit_p(PSTR("Relay No_1 is <a href=\"/?REL1\">$F</a><br>"),PSTR("ON")); if(rel2Status) bfill.emit_p(PSTR("Relay No_2 is <a href=\"/?REL2\">$F</a><br>"),PSTR("OFF")); else bfill.emit_p(PSTR("Relay No_2 is <a href=\"/?REL2\">$F</a><br>"),PSTR("ON")); // and html close, any footer goes here... bfill.emit_p(PSTR("<br></body></html>")); ether.httpServerReply(bfill.position()); } }
All LCD displays that are compatible with the Hitachi HD44780 driver has the following haracter map:
All above standard (?) characters can be printed with default library 'LiquidCrystal lcd' and use the lcd.write(number) command. the 'number' can be taken from above table when add the upper row number with the vertical (par example 43 is the + symbol). I found useful the characters 126, 127, 219, 223, 255.
As for graphics and custom characters this can been done with little more programming. Some examples can been found in the next pages
A 16x2 LCD panel with couple keys on board. on the manufactures site there is couple sample sketches but because the LCD is actual a standard 1602 LCD thus is capable to use any existing sketch compatible to the Hitachi HD44780 driver. The only change is to pin assignments so change in library declaration
LiquidCrystal lcd(12, 11, 5, 4, 3, 2) with this one: LiquidCrystal lcd(8, 9, 4, 5, 6, 7)
also I found the minimum cable to work the shield is D4 to D9, A0, +5V, GND and if you want access to reset button one more. I found usefulness this button maybe with one additional resistor this can be use in separate pin. The other five button they use single pin (A0) and with voltage divider it reads the button that pressed.
To minimize the flickering (in my case) I add delay(10) to the Key_Grab demo sketch.
I don't recommended for non experience people because the controller chip is SMD and thus is very difficult to replace in case of failure. But in the other hand the free space on the board is filled with pins with all analog and digital in/out.
Welcome to another blog about the famous arduino board. In this blog I will try to post my personal attempts experimenting with arduino together with varius sensors. I apologizeforany spellingmistakesbutmy Englishis notinthe best shape...