Showing posts with label sketch. Show all posts
Showing posts with label sketch. Show all posts

Saturday, 13 January 2018

Web-Configured ESP8266

A unique feature of Internet-enabled "things" is that they often have an Internet connection and little else. First-configuration of these devices therefore presents a challenge, which most solve by creating their own wireless access point, to allow their owner to supply credentials for the local wireless network.

Web-Configured ESP is an attempt to abstract away the boilerplate required for this task, and other related ones. It's a "starter" sketch providing the following basic features:

  • Creation of a temporary Access Point ("MyESP") allowing the configuration at the conventional url, http://192.168.4.1
  • A basic web-server running at this address, serving config.json and storing updates to it
  • An HTTP update server, allowing upload of new sketches "over the air"
  • An mDNS responder allowing access at http://myesp.local
Together, these features allow bootstrapping of sketches without requiring the devices to be tethered to a development machine, and user-provisioning of the finished article in the field.

Monday, 29 July 2013

Weather Guy


The picture shows a little Weather Station based around an ATmega328. What makes this one interesting is that it gets its weather data from Yahoo! Weather rather than a bunch of sensors. What's interesting about that (to paraphrase Dr Johnson) is that it can be done at all on an 8-bit microcontroller.

The hardware components of this system are not worth drawing a circuit diagram for:
  • Basic ATmega328 with 16MHz crystal and 22pF balancing capacitors (you know the score)
  • An ENC28J60 ethernet module (e.g., from eBay)
  • An ST7735 TFT display with SD-card (e.g., from Adafruit)
  • Stripboard, connectors, etc.
  • Err, that's it!
The software is where the real action lies. This baby (a 600+ line sketch!) crams in the following libraries:
The restrictions of the AVR chip steered the implementation in interesting directions:
  • All string constants stored in flash, using either F() or PSTR().
  • Using the TFT screen for debugging rather than Serial (saves 128 bytes RAM).
  • Graphics downloaded from Yahoo! in advance, converted into bitmaps and stored on a cheap SD card.
  • Buffer-sharing between the XML parser and reading from the SD-card. (In particular, most SD-card libraries require their own 512-byte buffer for output, see this earlier post.)
  • Reclamation of some flash on the AVR using Optiboot.
  • Displaying wind-direction without using transcendental functions (i.e., sin, cos) used the nice trick of successive rotations. (This is apparently due to the legendary Marvin Minsky, in hakmem 149.)
There is almost no free space left on the chip: just under 200 bytes of RAM (which I guess is needed for the stack) and 512 bytes of flash!

Here's another picture showing forecast data:


Saturday, 1 September 2012

USB IR Receiver


This is a little USB infrared receiver based on an original design by Ben Ryves. It pretends to be a USB keyboard and works by mapping NEC IR codes to keystrokes --- controlling the chosen application through its keyboard shortcuts. (VLC is a good choice of application because it's possible to change its shortcuts to match the ones sent by the receiver.)

I slightly simplified the hardware removing a switch which the original used to send different sets of key-codes, for two applications without programmable shortcuts. The modified circuit diagram is below.
(Note that the circuit must run at 12 MHz. I think this was due to the timing of the IR reception routine.)

I also simplified the software, removing a detection routine for the SIRCS protocol. Ben's original software is here, while my modifications are here.  The USB stack is V-USB: this is a nice simple example of getting started with it.

The software detects codes sent by a Newsky DVB-T remote control, seen below.
An easy way to discover the type of your remote control and the codes it sends, is with Ken Shirriff's handy IR library for Arduino; use the IRrecvDump sketch.

Friday, 12 August 2011

Twilight


The circuit above implements a light switch which is activated by darkness and movement, using an LDR and a PIR sensor respectively. It draws its power from the voltage it's switching, using a 7805 voltage regulator (on the left). A manual override switch is also provided.

The sketch below implements the brains of this circuit. Highlights are:
  • It smooths the light reading using an array of samples to prevent accidental triggering.
  • Hysteresis also helps with this, a light reading below the light threshold is definitely daylight, while one above the dark threshold is definitely night-time.
  • The light level is tunable using a potentiometer, when it's between the light and dark thresholds, an LED is lit indicating dusk.
  • Another LED is lit, using the signal from the PIR, when motion is detected. This is useful when positioning the box in daylight!
  • A manual override is provided to turn on the light for half an hour when it's daytime, and turn it off for 15s at night-time. (The latter allows the light to be turned off and the operator time to get out of the way.)
Several iterations were required to get the switching behaviour just right for the way it was to be used (in a kitchen). Had it been implemented using discrete hardware, it would not have been so easy to make these changes.



Thursday, 5 May 2011

Frankenstein's Thermometer

Not much more complicated than the simplest thing you can do with an Arduino is measure and display temperature. The picture shows such a device at the embryo stage.

The parts' list for this is:
  • 3x10k
  • 10k NTC thermistor (beta = 3977)
  • 100nF ceramic capacitor
  • 7x470R
  • Pushbutton switch
  • 7-segment LED display (common cathode)
The measurement is performed by a 10k resistor and the thermistor at the top of the picture. This is read by the Arduino on A5 and converted using the thermistor equation.

Each digit of the result is output on digital pins 2-8 in turn. A resistor is required for each segment of the display because otherwise the total current through the display would have to be shared between all of the lit segments; use whichever resistor-decade you have most of.

Finally, digital pin 9 is used to sense the state of the pushbutton. This allows cycling between centigrade, fahrenheit and the absolute temperature scale.

This circuit can be powered by 3v and draws between 15 and 30mA, depending on the digit displayed, indicating that the display is consuming the majority of the power. Thus, a couple of alkaline AAA cells would power this circuit for about 3 days.

If the thermistor is disconnected entirely, it displays -273C, which is nice.

Fritzing is here.