Showing posts with label WiFi. Show all posts
Showing posts with label WiFi. Show all posts

Tuesday, April 17, 2018

Upgrade your HDSP clock to an NTP-synchronized WiFiChron

So you have the simple HDSP clock but you wish you had the NTP-based time synchronization and the weather feature of the WiFiChron (not to mention the alarm). The "solution" is to buy the WiFiChron kit :)

The alternative "solution" is to hack your HDSP clock, by adding a proto-shield with an ESP8266 module, a 3V3 regulator (e.g. MCP1700) and a buzzer, the components that make the difference between the two clocks.


Before building the ESP8266 proto-shield, perform the following 4 modifications (highlighted in the next photo) on the HDSP board:
  1. isolate the FTDI's CTS pin (second from the top) by cutting its traces to the ground;
  2. wire the newly isolated FTDI pin 2 to pin 16 of the processor (D10, used for the buzzer);
  3. cut the trace connecting pin 1 of the LED display (RST) to pin 3 of the processor;
  4. solder the right angle FTDI male header on the back of the board, towards the USB plug.

The small proto-shield, that looks like in the photos below, will plug in the FTDI header. Naturally, the same FTDI header is used for either the FDTI breakout (to upload sketches) or the ESP8266 proto-shield.



Besides the hardware, one little software change (of the original WiFiChron sketch, available here) is required as well, due to the second button connected to A3 (instead of A1 as in WiFiChron):

    #define PIN_BTN_UP 17  // A3 in hacked HDSP
// #define PIN_BTN_UP 15  // A1 in WiFiChron

Since the 3rd button ("Down") is missing on the HDSP board, only the "Up" button function will be available (the left button).

Follow this post to set up the network connection.
And remember, the ESP8266 baud rate MUST be lower than 115200 (set it to 38400), since the ATmega328 with internal clock cannot handle this speed reliably (according to the datasheet, the drift is about 8%).


Monday, July 18, 2016

WiFiChron with ATmega1284

The WiFiChron code, with support for ESP8266, nearly reached the program memory limit of ATmega328, yet still missing a few features, the most important being the much needed debugging capability.

Naturally, the next step in WiFiChron's evolution was to upgrade to Atmega644P/1284P. Since there was no room on the board for the 40-pin DIP package, I settled for the SMD version.


The schematic is shown below.


Although functional, the board I designed is far from perfect:
  • requires pull-up resistors for buttons; I relied on software pull-up, but that does not work in the current Sanguino library;
  • requires a couple of more decoupling capacitors;
(I soldered all these extra parts on the bottom side of the PCB, as shown in the next photo. The 595 shift-register is soldered on the bottom by design. The next revision will have the currently missing parts in the SMD package.)
The WiFiChron-1284 board has the same dimensions as the previous revision, and it still fits in the Serpac A20 box.


I burned the bootloader using the on-board ICSP header.

Thanks again to MikeM, who contributed the software (Arduino 1.6.7 - compatible), featuring:
  • proverb display;
  • moon phases;
  • a few new menu options for user settings;
  • improved support for ESP8266;
  • integrated support for GPS module.

More on the code later.

Wednesday, June 24, 2015

WiFiChron fix and other WiFis

The peculiar feature of the "May 2015" revision of WiFiChron board is that it was designed to use software serial to communicate with either the XBee or ESP module. The reason is related to debugging. I wanted to be able to send messages to the serial monitor while (software serially) communicating with the serial device. This solution works well for XBee (GPSBee, BTBee), but not for ESP8266, only because the software takes more than the available 2K of RAM in this case (WiFi + software serial).

The immediate fix to use the ESP module is to connect its Rx/Tx lines to Rx/Tx of the processor. The existing connections can be left uncut, since they are not used in the sketch for ESP8266. The wiring should be like in the photo below.


The "permanent" fix would be re-designing the board to use ATmega1284 SMD (DIP-40 would not fit).

Talking about 1284, take a look at Farit's WiseClock4 mod. He used the WiseClock4 board, but completely re-wrote the software, including, it seems, the definition of new fonts. The SD card is now used for storing MIDI files (among others) that can play tunes through the Fluxamasynth shield.


A few of the other hardware and software features are:
  • WiFi access to the internet through WiFly module;
  • accurate time keeping through NTP;
  • display weather forecast read from the web;
  • daily alarms;
  • automatic adjustment of the display brightness with light sensor;
  • user-selectable display color.
The exquisite and elaborate wooden enclosure adds even more character.

And a photo of the internals, with the extra hardware:



Farit also shared the software he wrote, hopefully an inspiration for future mods.

Tuesday, February 24, 2015

WiFiChron clock kit now available

Update Sep 18, 2017: Here is the latest revision of the PCB included in the kit.

Update Oct 8, 2015: The latest revision of the PCB (pictured here and here) has hardware support for XBee (which also covers GPSBee, WiFiBee and BTBee).

With this kit you build a clock like the ones shown in the photos below.




Last one, courtesy of Nick, features an yellow/amber display.

There are two buying options:

1. use or make your own enclosure

 (US$47, free shipping to North America)


2. enclosure included (Serpac A20, transparent front panel, screws, back panel hand-drilled with 3 holes for buttons and rectangular opening for the USB connector)


 (US$61, free shipping to North America)

The kit includes the following electronic parts:

  • main PCB
  • display adapter PCB
  • ATmega328 with 8MHz bootloader, programmed with a clock sketch + 28-pin socket
  • 74HC595 shift register + 16-pin socket
  • HDSP-2534 8-character alphanumeric display + 4 x 6-pin machined headers
  • DS3231 + battery holder + CR1220 coin battery
  • LM1117 3V3 regulator
  • 3 x right angle push button
  • 5 x100nF capacitor
  • 3 x 10k resistor
  • 220uF (or so) electrolitic capacitor
  • 2 x 12-pin right angle male header
  • miniB USB connector
  • buzzer
Schematic and board layout are shown below.



The board supports other types of displays as well, through the use of adapters. So far, beside the HDSP-2534 coming with the kit, there are adapters for HDSP-231x and QDSP-6064 (the sketch is different for this one), shown below.



Assembling the kit

Finding the right place for the components on the board should be straightforward, since the silkscreen shows their values and their orientation.
It is very important to pay attention to a few aspects:
  • the orientation of the DS3231: the key (pin 1) must be the top-right on the board (so that you'll see the marking on the chip upside-down);
  • solder the USB mini-B connector BEFORE the capacitors surrounding it, or otherwise you'll be forced to solder the USB's ground and Vcc pins (the 2 extreme pins among the 5) in a very cramped space;
The procedure to attach the display is as follows:
  • first insert the little adapter PCB all the way into the right-angle headers, then the headers themselves into the main PCB; solder the headers to the main board first, making sure that the small PCB adapter is perpendicular on the main board;
  • solder the display adapter PCB to the male headers, after it's inserted all the way, with the so the headers' pins stick out;
  • cut the sticking pins to the PCB level; at this point you have the adapter attached and connected (perpendicular) to the board, and you are ready to solder the HDSP-2534 display;
  • insert the machined headers into the HDSP-2534 display first, then insert the HDSP-2534 display with the attached machined pins into the adapter PCB until all pins are accessible on the other side;
  • solder the machined pins, on the side facing the main board (the bottom row is just underneath the main PCB, the top row is above the main PCB). In the end, it should look like in the photo below.


Then insert the display with the key (the "cut" corner) in the left bottom of the adapter.

An assembly video can be also found in this post..

As of Oct. 8, 2015, an HCMS-29xx adapter is available (shared on oshpark), for use with the "serial"  intelligent displays (as opposed to the "parallel" HDSP-2534 coming in the kit).




Thursday, December 25, 2014

XBee-fy the ESP8266 WiFi module

With the new ESP8266 module, adding WiFi to any Arduino project became a lot cheaper.
This module has a serial interface; therefore it only requires connecting 4 pins: Tx, Rx, 3V3 and Ground, as shown in this image.

A few peculiar facts about ESP8266:
  • default serial baud rate is 57600; since this rate is too high for SoftwareSerial library, a hardware port should be used;
  • requires 3V3 for power and level shifting for Rx signal (5V to 3V3);
  • physical interface is a 2x4 pin male header;
  • firmware can be upgraded to a version that allows 9600 baud rate;
  • can be used either as client or server.
The first two characteristics makes it a perfect candidate for a module with an XBee footprint, as is WiFly, for example.

It took me about half an hour to do it, following these steps.
  1. cut a piece of 2-mm perfboard to the XBee dimensions;
  2. solder two 10-pin the 2-mm-spaced male headers on the sides;
  3. desolder (using wick) the 2x4 header;
  4. mechanically attach the header-less ESP8266 module to the XBee perfbord, by soldering 4 pins into the corner holes, aligned with holes in the perfboard;
  5. wire the pins 1, 2, 3 and 10 of the Xbee-type module to pins Vcc, Tx, Rx and Gnd of the ESP8266 module respectively.

And now a few photos. Start with these (XBee shown for comparison purpose):


to make this:



Then plug it any Xbee socket, like one on Wise Clock 4:


or Adafruit XBee adapter:


Hopefully now more people can try adding new WiFi features to their Wise Clocks without breaking the bank (paying $35 for WiFly).

Friday, February 22, 2013

User-friendly configuration of a Wi-Fi device

My previous post enumerated a few methods for configuring a device to connect to the home Wi-Fi network.
One of the friendliest way was number 4 (Creating a temporary ad-hoc Wi-Fi network). This method was chosen by Twine and also by HeatMeter and Belkin WeMo.

In normal use, the device connects to the home Wi-Fi network as a client, then sends (http GET/POST) the collected data to a web server.

Sometimes, when the device needs to be configured, it creates its own Wi-Fi network and runs a local web server. At this moment it allows other Wi-Fi devices (PC, smart phone etc) to connect, as clients, to the local web server and send configuration data, specifically the name of the home Wi-Fi network and the password. Once this configuration data is acquired and stored internally (in eeprom), the device returns to its normal state and uses it to connect to the home Wi-Fi network.
The configuration mode is selected by the user. One simple method is by holding down a button after a reset. Another is by placing the device (which has on-board accelerometer or even a tilt sensor) in a specific orientation (as done by Twine).

Below are diagrams I drew to show these two modes of operation (configuration mode and regular use mode).


















The steps are:
1.After reset, if a switch is pressed by the user, the board enters the configuration mode. This makes  the Wi-Fi module a Wi-Fi server.
2.The user connects to it from laptop. Then user is presented with a web page that contains a form allowing the selection of the Wi-Fi networks that were detected, and the password.
3.These 2 elements (network name and password) are then saved in the eeprom. They will be used later to access the Wi-Fi network any time the sensor data gets sent to the collection web server.




















Steps:
1.Data is read from the sensor.
2.Sensor data is sent as an http POST request through the Wi-Fi module.
3.Wi-Fi module posts the sensor data to the web server.



A nice feature for a network-connected device is that it can get program upgrades remotely, "over the air" in the case of Wi-Fi. This requires a bootloader that can connect to the internet and checks if a new version of the program is available for download on a given web server. The Readiymate team wrote such a bootloader for ATmega1280/2560 (the processor(s) found on Arduino Mega).

The next diagram shows how the remote program upgrade would work.


















The steps are:
1.Bootloader makes an http GET request through the Wi-Fi module.
2.Wi-Fi module passes the request the web server used for “program updates”.
3.Web server starts streaming the latest program file (sketch).
4.The sketch is uploaded into the program memory.

Monday, December 31, 2012

User interaction when connecting WiFi devices to network

I spent some time recently analyzing methods for passing the WiFi parameters (network name and password) to a device, in user-friendly manner and on the cheap (that is, by using minimum extra hardware).

This challenge (of selecting the WiFi and entering the network password) was already solved in many different ways, from using the remote control to select characters displayed on the TV screen (as done by Apple TV, XBox etc), to creating an ad-hoc WiFi network (as done by WiFi thermostats, Twine and others).

The bottom line is that every WiFi device must somehow present the users with an interface that allows them to type in the network password. How this is solved determines the user-friendliness of the device and influences the final cost of the product as well.

Here are the methods I found so far. I am sure this list will be extended and improved with details, hopefully also based on the readers' comments and feedback.


1. SD card that includes a text file with network name and password
The user edits the text file on any computer. The SD card is then transferred onto the device. After the device is powered, the settings are stored internally and the SD card can be permanently removed. 
Pros:
- user-friendly and almost fool-proof;
- easy to implement in software;
- SD card may be also used for storing other data (backup in case of network disconnect, power outage etc);
Cons:
- need access to a PC (any text editor would work);
- adds about $6 to the total cost of the device (SD socket, SD card);
- device may need to be shipped with a an SD card USB adapter (adds another $2).


2. Bluetooth – The user interface is provided by a smart phones that communicates with the device through Bluetooth.
Pros:
- very user-friendly user interface through the smart phone app (e.g. Android), that uses a full keyboard and a complete feedback (similar to text editor);
- easy to develop the software for Bluetooth communication for the device;
Cons:
- adds $5 to the cost of the device (BT module);
- a simple application (e.g. BlueTerminal) needs to be downloaded by the user on the smart phone;
- may not work with iPhone, which requires Apple-licensed BT modules.


3. Using QR code that ships with the device - patented, licence-able technology; to investigate further (price, complexity etc.);
Pros:
- (maybe) user friendly, with minimal user interaction: smart phone app leads to a web site that requires the user to input the password;
Cons:
- pay royalties;
- need smart phone with camera and software app for QR codes.


4. Creating a temporary ad-hoc Wifi network (as used by some smart WiFi enabled thermostats)
Pros:
- easy to use web interface;
Cons:
- need a computer that can connect to the existing WiFi;
- requires development of the web site (for inputting the password);
- requires a way to switch the device between the setup mode and regular operation (when already connected to the WiFi). (Note: The above mentioned Twine uses an accelerometer chip for this purpose.)


5. Include an LCD screen with touch sensor or buttons (as in Nest).
Pros:
- all inclusive solution, no other equipment required to interface with the user;
Cons:
- adds to the final cost (at least $4);
- may be cumbersome to use, since the display is quite limited in space;
- makes the device bigger;
- software to handle the user interaction can be quite complicated (for such a simple task);
- waste of resources, since the LCD screen and buttons/touch may be used only for this purpose (user input).


6. Use a wired (custom, non-PC) input terminal, with screen and keyboard, that communicates on serial (RS232, RS485, TTL) interface with the device.
Pros:
- simpler software (processing the commands received on the serial interface);
- does not require extra hardware on the device itself;
Cons:
- need to provide the terminal hardware as well (OK solution when the device installation is done by a trained person).


7. Use an infrared (TV, VCR, stereo etc) remote control
Pros:
- ubiquitous, everybody is guaranteed to have one around;
- software is relatively easy to develop;
Cons:
- user interface not friendly; it would require some user feedback (display);


8. NFC (Near Field Communication) - to be researched
Pros:
- friendly user interface through the smart phone;
Cons:
- requires a smart phone;
- need to develop app for smart phone.



9. Direct connection to PC through USB/FTDI cable - as done by the readiymate board
Pros:
- the simplest to implement method: the board's microcontroller listens to and interprets the serial commands from PC;
- change the network name and password through either the serial monitor (command mode style) or through a GUI app that translates button clicks into serial commands;
Cons:
- requires on board FTDI chip (adds about $5 to the board's cost);
- requires development of the PC (GUI) app that talks to the board;
- also requires the user to download and install the app on the PC.



Tuesday, October 9, 2012

Stock ticker with Wise Clock 4 and WiFly

I should have titled this "Adventures in WiFly land - Part 2", a continuation of this post, but really there was no adventure. Things worked smoothly from the start. The main "challenge" was parsing the http response on the fly, since the (truncated) response string itself is about 1500 bytes (3/4 of the RAM in a 328), which is the size of WiFly's receiving buffer.



The code (download from here) performs these steps:
  • send http request to yahoo site, specifying the stock symbol;
  • read the http response and find the token that identifies the stock price, in this case "last:";
  • read the next few characters that represent the stock price;
  • display the symbol and the price on the 3216 display.

This crude version is based on the WiFly_WebClient sample code from sparkfun. For display, it uses the HT1632 (header and c) files that are part of Wise Clock 4 library (but also supplied in the zip file). The software should work with any Arduino connected to a serial WiFly and a 3216 display from Sure Electronics.

The plan is to integrate this code as a new application in the Wise Clock 4 software. Stock symbols should be user-configurable and read from the SD card (as opposed to being hardcoded as they are now).
Also, the direction of the stock move, read from the http response as well (after the token "change"), could be shown in red for "down" and in green for "up".

Thursday, September 6, 2012

Post data to cosm.com with WiseClock4 + WiFly

Last weekend I re-discovered cosm.com, formerly known as pachube.com.
After spending a lot less time than I had planned (since things went so smoothly), I was about to post details about the experience; then I saw this fresh post on sparkfun, which pretty much explains everything one needs to know about creating an account and sending data.

The main difference between sparkfun's setup and mine is the connection to internet: I used the WiFly module plugged into the WiseClock4 board. Therefore, the code is a little bit different too: I used the great WiFly library, which even comes with a (little dated) "pachube client" example. All one needs to do is provide the right parameters (app key, network ssid, password etc) in credentials.h, then change all references from "pachube" to "cosm".

As a quick experiment, I read the value from (disconnected) A0 every 25 seconds, and this is how the cosm graph looks like:









A user-friendly cosm-client device based on WiseClock4 with WiFly (which, by the way, seems to be the cheapest way to connect to a WiFi network) would read the configuration parameters from a file on SD card (then, for security reasons, delete the file and store those parameters in eeprom) or provide a way to receive these parameters (ssid, password, app key etc) from a smart phone through bluetooth.

(To be continued)

Sunday, January 15, 2012

Adventures in WiFly land - Part 1

This was a bit of a struggle, working with the XBee-footprinted WiFly RN-XV module from Roving Networks.

The goal was to get some data from the RSS feeds, kind of what this project had achieved.

First, I tried to set up the RN-XV module following this crash course (and using ladyada's XBee adapter with the FTDI cable). Everything went fine except connecting to my home WiFi network: I kept getting "AUTH-ERR". Eventually, after many tries, the module joined the network. I thought this is caused by the weak WiFi signal and other people may experience a similar scenario (which should be dealt with by the software).
Then I found with this software library, which, of course, did not work in my special case. After I started tweaking it and read the RN-XV manual once again, I found the explanation: WPA (which I am currently using) handshaking takes more than 1,000ms (1 second), which is the default timeout for the module. The solution was to increase this timeout (to 5000ms) with the command

set opt jointmr 5000

I ended up writing this sketch that makes requests to Yahoo's weather and stock quotes RSS feeds. It should work with the mentioned WiFly library (if they don't keep changing it).
Actually, I had to modify the library a bit too, to include my own specific commands in the initialization procedure. So I created this new function

boolean WiFlyDevice::myInit()
{
  if (!enterCommandMode())
  {
    DEBUG_LOG (1, "Failed to enter command mode");
    return false;
  }

  // turn off remote string;
  sendCommand("set com remote 0", false, "AOK");

  return sendCommand("set opt jointmr 5000", false, "AOK");
}

then modified begin() to look like this:

void WiFlyDevice::begin() 
{
  DEBUG_LOG(1, "Entered WiFlyDevice::begin()");

  if (!bDifferentUart) SPIuart.begin();
  myInit();
}

Another detail worth mentioning is the tuning of the delay between sending the request and reading the response. If this delay is too long, the response buffer gets overwritten, so response data is lost. If the delay is too short, the response is not there yet. Similar consideration while retrieving the response data from the buffer: we need to wait a bit for more data to come before we can say (kind-of) for sure that all data was received.

Next step (Part 2) is to parse the responses to find the correct values we are looking for, temperature and stock price, respectively, then to display them on Wise Clock 4.

Note: The RSS feeds I used are 
and
They could be custom-replaced with any other URL that returns a small(ish) set of XML data for easy parsing.