Training Session 3:
Introduction to advanced sensors: precalibrated digital sensors - low cost and easy to use
1. Timing in XOD: a traffic light
A traffic light is a good example of a device which does its job sequentially. In its simplest form a traffic light has three states:
Green — go
Yellow — stop if you can
Red — stop!
Each state is active for some time interval and when done everything starts from the beginning and repeats again and again. Doing things sequentially in XOD can appear hard at first sight. It’s a bit harder than in traditional imperative languages, but not so complicated if you would remember the pattern:
Understand your sequence states
For each state make a patch node
On each state patch, use pulse inputs and outputs to enter and exit the state
Make a joining patch which wires all states together
Define an entry pulse for the first state
The XOD tutorial at: https://xod.io/docs/guide/simple-traffic-light/ demonstrates the creation of a node from an existing patch, and then use of the new node and management of timing in XOD. (Code has been customised by Marco Aita for our hardware).
2. Multi-function shield II
The next part of the tutorial tutorial will focus on the availability and use of low cost, high precision sensors that can be easily used for scientific purposes. We will also introduce the use of a second multi-function shield that will provide some useful features for the use of sensors. The shield contains:
4 digit 7-segment LED display module (3641BH) driven by two serial 74HC595’s (Pin Latch 4, Clock 7, Data 8)
4 Red LEDs (Pin 10,11,12,13) [D1-13, D2-12, D3-11,D4-10]
10K potentiometer (Pin A0) [Vr-A0]
3 x push buttons (Pin A1, A2, A3) [S1-A1, S2-A2, S3-A3]
Piezo buzzer (Pin 3 digital ON/OFF) [LS1-3]
DS18B20 temperature sensor interface (not included) (Pin A4) [U5-18b20-LM35-A4]
Infrared receiver interface (Pin 2) [U4-IR-2] Compatible to a 1838B Infrared IR receiver
Bluetooth interface (GND, +5v, 0 = tx, 1 = rx) [APC220]
Free pins pwm (5, 6, 9, A5) with GND, +5V
Serial interface header for connection to (optional) serial modules (Bluetooth, wireless interface, voice module, a voice recognition module)
The Hackatronics section of the Cohesive Computing site (http://www.cohesivecomputing.co.uk/hackatronics/) provides an excellent source of information about this shield, along with Arduino IDE code to drive features of the board. Support for XOD, a relatively new platform, is less well developed, but growing rapidly. Our tireless Biomaker support crew have produced custom nodes and patches to help exploit the shield.
3. Triggering the buzzer
We have compiled a XOD library that contains nodes and patches that you can use to provide audible output. The buzzer on the shield can be triggered to produce timed output of defined frequency (tone). A transistor is used to control the piezo speaker (LS1) - which is activated when the output port D3 is set to zero (Unlike the buzzer on the Multi Purpose shield used in Training Session 1 & 2, there is no need to drive a oscillating signal through LS1, it is set automatically).
4. LED 7-segment display
The tutorial library for training session TWO also contains support for other components on the shield, including switches 1 (port A1), 2 (port A2) and 3 (port A3); the variable resistor (port A0) and bank of 4 red LEDS (ports D1-D4).
In addition, the shield has a 4 digit 7-segment LED display. The digits are made up of seven individual LED segments, which must be controlled to form particular numbers.
The shield is wired with two 74HC595 shift register chips that each take an 8-bit serial input and decodes this to provide 8 parallel outputs. Suitable serial codes are sent to the circuit to control the display of numbers on the display. Marco Aita has wrangled code that allows the circuit to be used inside the XOD environment (with thanks to Arduino Learning).
5. Real time clock
I2C Tiny RTC DS1307 Real Time Clock Module AT24C32 Board for Arduino (Battery included)
Two wire I2C interface
Hour : Minutes : Seconds AM/PM
Day Month, Date - Year
Leap year compensation
Accurate calendar up to year 2100
1Hz output pin
56 Bytes of Non-volatile memory available to user
DS1307 is a low-power real-time clock chip with 56 bytes of non-volatile RAM, full BCD code clock and calendar. The address and data will be transmitted via a two-wire bidirectional serial bus, and the chip can provide information such as seconds, minutes, hours, etc., and the number of days in each month can be automatically adjusted. Besides, there is a compensation function for leap year. AM / PM flag is to determine whether the clock operates in 24-hour or 12-hour mode, and there is a built-in power-sense circuit in the chip with powering down detecting and battery switching functions.
6. DS18B20 temperature sensor
The new shield provides support for the DS18B20 digital thermometer chip. Note that Jumper one (J1) must be added to allow the sensor to work.
DS18B20 digital temperature sensor adopts single-bus technology, which can effectively reduce external interference and improve the measurement accuracy. Meanwhile, it can convert the measured temperature directly into a serial digital signal for computer to process. With simple interface, it makes data transmission and processing much easier.
7. Additional I2C sensors
1-Wire and I2C are true shared-bus protocols - you can have 100+ components all talking at once using the same 2 wires (for I2C) or a single for 1-Wire. I2C (Inter-Integrated Circuit) is a faster and more open standard, and many sophisticated (and often cheap) digital devices are available for connection.
List of I2C devices and addresses compiled by Adafruit
XOD provides a series of I2C primitives that can be combined to create custom patches and nodes.
Download software library
The starter code for Tutorial Session Three can be downloaded. Marco Aita has compiled a series of patches and nodes for this training session, which can be obtained from the download page