Flock of young Jackdaws begging food, Whitchurch, Hampshire

Flock of Jackdaws with young in trees by playing fields and trees by the River Test in Whitchurch. The calls of the young from all around come out in this binaural recording.

remote sensing LLAP to SMS gateway

Our smallholding is an island site with no power and no broadband. No power means things like a Raspberry Pi are marginal – we’re looking at a current drain of about 500mA for a Model A. For a 85AH leisure battery of which you only want to use half the capacity for good service life that’s about 80 hours. So it’s time to look at the system architecture of a remote sensing network to try and reduce the power used at the remote site. The aim is to offload the processing for graphing to a site with mains power (home), so the system has sensors, a gateway that collates all the sensor data and sends it via SMS in my case, and a data processor.

Remote sensing network system architecture

At a site with mains power the gateway and data processor can be the same thing. The architecture of such a system is therefore two-level –

  • many sensors out in the field
  • a gateway/data processor

At home I have a Raspberry Pi that collects data from my sensors using a RF board, Ciseco’s Slice of Radio. The same Raspberry Pi runs RRDtool to do the graphing and SFTP to put the graphs onto the web.

Sensor network on a mains-powered sirte - the Raspberry Pi does most of the work
Sensor network on a mains-powered site – the Raspberry Pi does most of the work

At the farm, however, because of the power constraint I need to use a gateway to transfer the data onto the mobile network using SMS.

That sort of site typically consists of three levels –

  • many sensors, out in the field doing the data collection,
  • a gateway, that collects all the sensor data
  • a data processor – that consolidates the data from the sensors, graphs it and saves it, perhaps uploading to the web

So the next stage down from a Pi is something like an Arduino

The Arduino OKG and Sainsmart SMS to serial device reduce power usage by 80%
The Arduino OKG and Sainsmart SMS to serial device reduce power usage by 80%

The Raspberry Pi can be at home so its power consumption isn’t an issue any more. It takes an SMS message of various sensor readings and munges this via Python and some scripts into a RRD database which then goes with RRDgraph. Which gives the single-sensor plot as shown below. The battery voltage chart shows that something rather nasty is happening to the main battery – it looks like the charge controller is not disconnecting the solar panels from the battery when the battery voltage is high enough – if so this is the second Kemo charge controller I’ve had from Maplin that has failed in service.

Simplified sensor chart
Simplified sensor chart

What, no IoT platform?

I’ve gone off third-party IOT services, because the RPi lets me run RRDtool, and shifts the conversion from simple CSV text files to home. I get to control what goes on, I am not subject to the whim of third-party changes, cessations of service, charging for what was free and all the other hurt that goes with relying on people you don’t pay. I found the Xively Arduino stack memory leaky and buggy despite my initial enthusiasm, and now I can run a Raspberry Pi at home I can insource the job, and get the Ethernet stack off the Arduino.

In that way the data gets processed more as it is staged along the signal path as the processing power of my devices and electrical power available to them increases. Electrical power is shortest at the sensor, which draws an average of about 1mA. It gets consolidated at the OKG gateway, which is powered by a 12V leisure battery and draws about 60mA, handling all the sensors. Once it gets to the Raspberry Pi at home that is mains powered I can live with the 500mA-700mA@5V and that does the collating, data transforming into a RRD database, graphing and uploading to the Web.

Sensor design

For my system architecture I have pinched ideas from the design of industrial process control system – historically these used wired sensors, firstly using 4-20mA analogue signalling using current (this independent of wire resistance). With zero response the sensor would draw 4mA and at full scale it would draw 20mA. These fed into a console for display.

However, I don’t want to run wires all over the farm, so I will use Ciseco’s LLAP serial data format over radio. This replaces the naalogue current loops and wiring and lets me reduce cost and power at the sensor, which can sleep for most of the time, only waking every 10 minutes to send a 12-byte packet on the radio network to be received at the gateway. That’s just as well, since losing the wiring means the sensors each have to be autonomously powered.

thermistor board with XRF
Ciseco’s thermistor board with XRF

Ciseco already make some sensors using the processor on the XRF radio – you simply upload a different firmware to the XRF – there’s an example in the picture, and this is powered from a CR2032 coin cell on the board just under the XRF.

thermistor board in box
thermistor board in box

These make a neat small sensor, and great for measuring the temperature in a shed where sunlight doesn’t fall directly on the black box (generating large readings unrepresentative of the air temperature) but they aren’t great for soil temperature measurements.

soil temperature measurements from a buried probe and a LLAP thermistor sensor in black box on the soil surface
soil temperature measurements from a buried probe and a LLAP thermistor sensor in black box on the soil surface

The blue line is the LLAP sensor in a box – placed next to the soil sensor – they are physically very close, but the box on the soil experiences a much wider temperature range!

Sensors deployed in a polytunnel
Sensors deployed in a polytunnel

Not only is there the sunlight problem, but being on the soil keeps the radio low which minimises range, hence the choppy blue line. However, it wouldn’t be hard to mod one of these with a jack switched socket to use an internal thermistor unless an external one was plugged in, and they’re quick and easy to deploy, which is great. They can also be run off two NiMH AA cells instead of the Li battery, which opens up the possibility of using solar power for unattended operation (the CR2032 battery is good for 6 months at least at a 10min update rate).

To get more out of the limited data rate on the SMS gateway, I’ve also got a LLAP sensor design with two sensors and a PIC microcontroller than encodes two temperatures onto one LLAP packet. I use two of the the Dallas18B20 digital temperature sensors for that.

PIC miocrocontroller/XRF dual dallas 18B20 control box
PIC microcontroller/XRF dual dallas 18B20 control box. Powered off 4xAA NiMH maintained by a solar cell

The Gateway

Ciseco do a Arduino Uno based gateway PCB that has an UNO and sockets for their XRF modules, called the OpenKontrol Gateway. This also has space for a Real Time clock which is nice. I only needed the Arduino, the RTC and the XRF hence the gobs of unused space on the LHS. I wired this via the serial port to a Sainsmart TC35 used as a SMS gateway, mounted on the bottom of the box. Unfortunately the XRF ends up between two ground planes, which doesn’t do wonders for the RF sensitivity. However, I was ready for that, bringing out the serial connections to a DIN socket, so I can mount the XRF remotely and up high if necessary, taking just power and 9600-baud RS232 back to the box.

Ciseco OpenKontrol Gateway on lid of device, with Dallas 1307 RTC implemented
Ciseco OpenKontrol Gateway on lid of device, with Dallas 1307 RTC implemented
the finished LLAP to SMS gateway
the finished LLAP to SMS gateway

So far I have learned a lot from this deployment – it’s proved the principle, but I need to improve the RF performance of the OKG/SMS gateway with a remote XRF receiver to be in with a good chance of covering a significant part of the smallholding.

how to measure AA battery capacity

Poundland in the UK sell batteries branded by Kodak, but the cheapest ones are zinc chloride. I thought ZnCl has gone out of use decades ago, but it is surprising how often people are penny-wise and pound foolish. Particularly in pound shops 😉

Cheap Poundland batteries are in fact twice as dear to use!
Cheap Poundland batteries are in fact twice as dear to use…

So I am looking to make something to track the discharge of a battery. This is also useful to qualify NiMH and NiCd batteries – these fade with time and it is good to know what sort of capacity is left.

...as the expensive ones!
…as the expensive ones!

Every minute it reports the voltage and current from the batteries running through a 2.5V torch bulb, the third bulb is maintained at 2.5V to provide a reference. It transmits the signal using radio to a datalogger. I got a camera to take a picture every 15 minutes, as a video the results are reasonably clear. A picture tells a thousand words – the Zinc Chloride batteries are crap

The left-hand bulb is powered by the ‘cheap’ battery that Poundland sell for 9p, the middle is powered by the ‘dearer’ alkalines they sell at about 17p.

Bulb measurement schematic
Bulb measurement schematic

I have a Ciseco OpenKontrol Gateway as a datalogger. It stores data to a SD card, but there is no law saying you couldn’t send it to some kind of IoT host like Xively. So all I need is the interface to the batteries to track the voltage and current; I used a 2.5V torch bulb for the load because it does not seem unreasonable to me to expect batteries to be used in a torch, I use two batteries in series, which seems to be the most common configuration in a torch. On the way to ground I use a 1 ohm resistor so I can measure between ground and the top of the bulb the battery voltage and between the resistor and ground the voltage corresponding to the current. Using 1 ohm makes the calculation easy, and also drops about 0.3V so the bulb is run at 2.7V at the start.

Now if you are looking to do this in a big way then these guys at Battery Showdown are doing this is a more rigorous way but their hardware is dearer. I’m also not absolutely sure that a constant current discharge is typical of many loads. something like a digital camera with a switch mode PSU actually increases its peak load with decreasing battery voltage because it is more a constant power device and needs to draw more current at a lower voltage to run the focusing bits. Something with a linear voltage regulator is a constant current to the dropout voltage of the regulator, but you don’t often see linear regulators in battery-powered kit.

The bulb isn’t ideal either, with a varying resistance with temperature, so I’d probably favour using resistive loads, and getting four/five battery channels instead of two. But the visuals were great for the video.

If you have a PC that can take RS232 then simply wire the output of the PIC to the PC serial port via a Max232 chip or single transistor inverter if you don’t need the radio connection. Since I have the datalogger logging other sensors it seems easy enough to use it as is.

I used a PIC16F870 that has five A/D channels – this gives me two battery channels. Each battery channel has one A/D port connected to A in the diagram, another one to B and 0V is connected to C. The voltage at B is the same as the current since R is 1Ω and the voltage at A is the battery voltage itself. The 10-bit A/D converter goes up to 1024, by setting the reference voltage to be the PIC power supply at the high end and PIC ground at the low end I made the maths easier by setting the PIC supply voltage to 5.12 V (this is within the PIC operational voltage spec of 4 to 5.5V) in which case a straight divide by two gives V in * 100, and matches the requirements acceptably.

Doing this for the Poundland batteries shows the difference between the alkaline and the ZnCl batteries

alkalines give about three times the runtime than ZnCl
alkalines give about three times the runtime than ZnCl

If we take the service life as down to 2V from 3V initially, then you get 1.7 hours from the cheap ones and 5.8 hours from the alkalines.Alkaline cost/hr is 17*2/5.8=5.9p/hr and the cheap batteries cost 9*2/1.7=10.6p/hr.

As a result you pay about twice as much to run something using the cheap Poundland batteries, and you get to replace the batteries three times as often. Saving money therefore costs you a fortune in aggravation and generates more waste. You also have this sort of problem if you don’t pay attention and leave the used batteries in too long.

cheap batteries consume the zinc outer casing, leading to this
cheap batteries consume the zinc outer casing, leading to this

The device offers an insight into the capacity of rechargeable batteries which is the more useful feature of it.

a very old pair of 500mAh nicads and a pair of Uniross 2300mAh NiMh
a very old pair of 500mAh nicads and a pair of Uniross 2300mAh NiMh

I am not really sure I understand the pathology behind the second wind the NiMH cells seem to have. I’d discard it as a fault in reading except that – the current shows the bulb did not blow or become loose, and the A/D and voltage reference is multiplexed, so the error should have shown elsewhere.  will repeat this and see if it happens again – probably not as this battery has been totally flattened so it is not the same battery.

For rechargeables I will modify this rig to take four individual cells and discharge through four resistors. That way I don’t back-charge any weak cells, and I don’t need to measure the current as the terminal voltage and Ohms Law will tell me the current. If I run 2.7Ω I will run about 440mA.

 

 Schematic

PIC battery tester schematic

JAL code

The JAL code for the PIC is 1311_datalogger_v06.jal

-- JAL 2.4i
-- derived from univ-sensor_v06
-- Datalogger
-- adjust power supply to 5.12V using the LM317 regulator.
-- internal Vref = VCC = 5.12V
-- Can just divide ADC by 2 and shift dec point by two places
-- v06 12 Nov 2013 RM
-- CC BY-SA 3.0
-- http://creativecommons.org/licenses/by-sa/3.0/
-- serial port designed for use with a Ciseco XBBO board and radio ( Google it)
-- can also use w/o radio via a Max232 or a FTDI adapter instead
-- radio is powered down while ADC measurement made to avoid loading regulator voltage

include 16f870
pragma target clock       4_000_000
pragma target osc    HS   ; use a 4MHz crystal or resonator
pragma target WDT    ENABLED
pragma target PWRTE  ENABLED
pragma target BROWNOUT    ENABLED
pragma target LVP    DISABLED
pragma target CP    DISABLED
pragma target CPD    DISABLED
-- HS, -BOD, ,-LVP, -WDT, -CP  = 0x3F22
;pragma target fuses       0x2007

include pic_general
include print
include format

-- set all interrupt sources disabled
;INTCON = 0

-- ADC includes delays so don't include this myself

-- V2 delay's
-- include delay_any_mc

-- more delay functions
-- include extradelay

-- the analogue pins
pin_a0_direction = input
pin_a1_direction = input
pin_a2_direction = input
pin_a3_direction = input
-- there is no a4 analogue channel
pin_a5_direction = input

pin_c7_direction = input
pin_c5_direction = output
pin_c6_direction = output

pin_A4_direction = output          ; this is open drain so 3V3 pullup comes from XRF
alias xrf_sleep is pin_A4          ; pull this low to start the XRF, let go and float up to enter sleep
xrf_sleep=low                      ; must enable with ATSM2

-- now configure ADC  (this is a 10-bit ADC)

const bit ADC_HIGH_RESOLUTION = true
const byte ADC_NCHANNEL = 1
const byte ADC_NVREF = ADC_NO_EXT_VREF
include adc
adc_init()

-- ok, now setup serial, we'll use this
-- to get ADC measures

-- all this is because the 16f870.inc file is not right for serial hardware  8/5/13
alias RCIF IS PIR1_RCIF
alias TXIF IS PIR1_TXIF
alias BRGH IS TXSTA_BRGH
alias RCIE IS PIE1_RCIE
alias TXIE IS PIE1_TXIE
alias TXEN IS TXSTA_TXEN
alias TRMT IS TXSTA_TRMT
alias SPEN IS RCSTA_SPEN
alias OERR IS RCSTA_OERR
alias CREN IS RCSTA_CREN
-- end of
-- all this is because the 16f870.inc file is not right for serial hardware

alias PEIE IS INTCON_PEIE
alias TMR1IE IS PIE1_TMR1IE
alias CCP1IF IS PIR1_CCP1IF

OPTION_REG = 0b00001111 ; PS asllocated to WDT and slowest rate selected (20ms*128)
PEIE = high
TMR1IE = high
T1CON=0b00110001        ; set timer 1 running internal osc 8xprescaled
CCP1CON=0b00001011      ; reset tmr1 on match, kicks off an A/D conversion
                        ; these next values seem to call a period of 10s from previous project
CCPR1H=244              ; decimal
CCPR1L=36               ; decimal
-- so count is 244*256+36 = 62500 At 4MHz each tick is 1uS, prescsaled by 8 to 8uS ticks.
--
const byte cyclesmax=60*2   -- how many times to count 0.5s ticks

var word mincounter = 0
;var byte lastTMR0=0
;TMR0=0   -- clear at start

-- ok, now setup serial;
const serial_hw_baudrate = 9600
const bit usart_hw_serial = TRUE
const bit lowspeed=true
include print
include serial_hardware
serial_hw_init()

const byte booted[] = "aVVSTARTED--"
const byte prefix[] = "aVV"
const byte line1[] = "+++"
const byte line2[] = "ATSM2r"
const byte line3[] = "ATACr"
const byte line4[] = "ATDNr"
const byte line5[] = "ATID0AFFr"
const byte vpfx[]= "VLT"

procedure WaitOnOk() IS
-- state machine - aim is to hang and
-- if this doesn't get to 2 the WDT will start things over after 2 sec
-- if it gets to 2 it clrwdt anbd returns

var byte state=0
asm clrwdt
while state !=2 loop
if serial_hw_data_available then
   if state==0 & serial_hw_data == "O" then
      state=1                        ; this is the only way to get to state 1
   end if
   if (state == 1) & (serial_hw_data == "K") then
      state=2
      else
      state=0                        ; because O was followed by something that wasn't K
   end if
end if
asm clrwdt
end loop

end procedure

procedure justify(word IN myval)  IS
-- value is going to be 0..1024 (in reality 0..512)
-- hundreds are integers, ie 2 d.p.
-- assumes radio is up and running
  format_word_dec(serial_hw_data,myval,3,2)  -- 0   .23
  serial_hw_data="-"
end procedure

function get_volts() return bit  is
  var word reading1
  var word reading2
  var word reading3
  var word reading4
  var word reading5
  asm clrwdt
  -- get ADC result, high resolution
  reading1 = adc_read_high_res(0)/2
  asm clrwdt
  -- get ADC result, high resolution
  reading2 = adc_read_high_res(1)/2
  asm clrwdt
  -- get ADC result, high resolution
  reading3 = adc_read_high_res(2)/2
  asm clrwdt
  -- get ADC result, high resolution
  reading4 = adc_read_high_res(3)/2
  asm clrwdt
  -- get ADC result, high resolution
  reading5 = adc_read_high_res(4)/2
  asm clrwdt
  -- send it back through serial
  xrf_sleep=low                                    -- start the radio a little before the data will be sent.
                                                   -- may want to change the LLAP prefix and comma del if not using radio
  delay_100ms(2)
  asm clrwdt
  print_string(serial_hw_data,prefix)
  print_string(serial_hw_data,vpfx)
  serial_hw_data="A"
  justify(reading1)
  asm clrwdt
  delay_100ms(5)                                   -- no need for this dela if going straight out on serial
  print_string(serial_hw_data,prefix)
  print_string(serial_hw_data,vpfx)
  serial_hw_data="B"
  justify(reading2)
  asm clrwdt
  delay_100ms(5)                                  -- allows the LLAP data to be received properly
  asm clrwdt
  print_string(serial_hw_data,prefix)
  print_string(serial_hw_data,vpfx)
  serial_hw_data="C"
  justify(reading3)
  asm clrwdt
  print_string(serial_hw_data,prefix)
  print_string(serial_hw_data,vpfx)
  serial_hw_data="D"
  justify(reading4)
  asm clrwdt
  delay_100ms(5)
  asm clrwdt
  print_string(serial_hw_data,prefix)
  print_string(serial_hw_data,vpfx)
  serial_hw_data="E"
  justify(reading5)
  asm clrwdt
  delay_100ms(2)                                         -- let the signal be transmitted and buffer empty
  xrf_sleep=high                                   -- stop the radio ftre the original data sent
  return true

end function

-- MAIN PROGRAM START

asm clrwdt
asm sleep                           ; use the WDT to delay about 2s to
                                    ; boot the sensor  and radio
asm clrwdt

-- now initialise the XRF to the system network ID and enable sleep mode
-- clear out any pre-existing RX buffer
var byte rxd
while serial_hw_data_available loop -- check if data is ready for us
  rxd = serial_hw_data          -- get the data
end loop
rxd=" "

if true then                        ; loop is simply to enable/disable
                                    ; if you have no radio then use if false then
asm clrwdt                          ; this setup routine for testing
xrf_sleep=low
                                    ; setup the radio using AT commands
print_string(serial_hw_data, line1) ; send +++
WaitOnOk
print_string(serial_hw_data, line5) ; change network with ATID0AFF
delay_100ms(1)
print_string(serial_hw_data, line2) ; enable sleep mode with ATSM2
delay_100ms(1)
print_string(serial_hw_data, line3) ; and use it - send commit
delay_100ms(1)
print_string(serial_hw_data, line4) ; ATDN we are done configuring
delay_100ms(10)
print_string(serial_hw_data,booted)
delay_100ms(2)
xrf_sleep=high                                    -- power down the radio
end if

forever loop

asm clrwdt
if CCP1IF then
   CCP1IF=false;
   mincounter=mincounter+1
end if

if mincounter >= cyclesmax-1 then
   mincounter=0
   var bit b = get_volts()
end if

end loop

 

AM2302 (DHT22 ) Temp Humidity sensor and JAL on a 16F628 at 4MHz clock

Having decided I can’t be bothered with digital sensors with oddball serial interfaces like the DHT22 it was time to suck it up when I needed a number of sensors. Cost adds up with lots of sensors – though that Honeywell product more than paid for itself a few times over in much better hatch rates (fertile eggs are about £2 a pop by post, that’s how much of a loss you eat for every failure to hatch!) not every sensor application affects the bottom line like that. Sometimes low cost trumps accuracy, reliability and serviceability. Enter the AM2302, apparently a.k.a. DHT22, produced by the fine Aosong corporation. Their website looks like line noise on my browser, but apparently they are based in Guangzhou, which is China’s third largest city, a conurbation of nearly thirteen million souls.

AM2302, humidity and temperature sensor, a.k.a. DHT22 apparently
AM2302, humidity and temperature sensor, a.k.a. DHT22 apparently

The sensors are cheap, nasty and have poor accuracy, but the price is right, it’s the cheapest way to get a humidity and temperature sensor. Five for £17.70 or a unit price of £3.54 from a Chinese supplier on ebay, Buyincoins ISTR. They have a non-standard one-wire interface. That requires you to be able to tell a 30μS high duration from a 68μS high duration. No problem, eh, even with a PIC running on the internal 4MHz oscillator so each clock cycle is 1μS?

There was already a JAL library for this, called temperature_humidity_dht11.jal so I am in development heaven.

Except it doesn’t work – it acts up after about 20s in the video. It sort of works some times, tantalising short runs of OK in amongst loads of timeout errors. I fiddle with the power supply a little as the AM2302 is claimed to be finicky on the need for 5V. No luck. Tracing the library code I find it barfs around

Continue reading “AM2302 (DHT22 ) Temp Humidity sensor and JAL on a 16F628 at 4MHz clock”

16F628 PIC A/D using JAL

The 16F628 pic doesn’t actually have a A/D converter. It has a couple of comparators and a software controllable voltage reference which does pretty well for most applications. I’m looking at using it for a low-battery cutoff device to protect 12V lead-acid batteries.The two comparators would work for that – one for the low-water mark, and one set a little bit above for a level the charge needs to reach before the load is reapplied, with some time delay probably too.

However, I came across Microchip’s Application note AN700 Make a Delta-Sigma Converter Using a Microcontroller’s Analog Comparator Module which shows how to use the comparator as an A/D  converter. There are plenty of PICs that already have an A/D converter – the 16F88 has several analogue channels, but the 16F628 is cheaper. A lot of applications need just one analogue value sampled, and my application also wants an A/D that includes 12V. If I used a chip with an onboard A/D I’m going to need two resistors anyway to pad 12V down to the 5V range, and AN700 fig 7 shows how to take advantage of the external parts to shift the A/D range up to about 12V.

Trouble is, I want to use JAL, to make life easier when I write the rest of the code, and the assembler mode of JAL didn’t work. I swiped this from here probably derived from here but it didn’t work for me. I took a look at the code and suspected the assembler part, because what was happening was as soon as I called the DeltaSigA2D() the whole program seemed to sit down and start again from the top, resulting in endless printing of “STARTED” and little else.

Thinking about what JAL is probably doing with assembler, I suspected some of the clever space-saving constructs like the bit in eat5cycles that goes

goto +1

which was supposed to be

goto $+1

could be asking for trouble unless I could really assume that next instruction is the next one in the program space. In the end if you’re going to use something like JAL you aren’t trying to eke out every last drop of code space, so I figured I would nut the cleverness and use stacked nops. And it worked.

 

-- JAL 2.4i
-- Just the A/D 15 June 2013
-- modded by Richard
--
-- adc_test_16f628_v03
-- after DeltaSig.asm v1.00 from Dan Butler, Microchip Technology Inc. 02 December 1998
-- after http://den-nekonoko.blog.so-net.ne.jp/2010-11-25 and AN700
-- continually spews 10-bit value on TXD at 9600 baud, 5V=1024 0V=0
-- AN700 Fig 2
include 16f628_inc_all
-- We'll use internal oscillator. It work @ 4MHz
pragma target clock       4_000_000
const word _fuses         = 0x3fff ; default value
pragma target osc         INTRC_NOCLKOUT
pragma target WDT    off
pragma target MCLRE  off
pragma target PWRTE  on
pragma target BODEN    on
pragma target LVP    off
-- HS, -BOD, ,-LVP, -WDT, -CP  = 0x3F22
; pragma target fuses       0x3D02
--enable_digital_io()

; const bit enhanced_flash_eeprom = false
include pic_general
include delay

var word result
var byte result_l
var byte result_h
var byte counter1
var byte counter2

const byte booted[] = "STARTED"

pin_a0_direction = input
pin_a1_direction = input
pin_a2_direction = input ; comparator in / vref out
pin_a3_direction = output ; comp1 out
pin_a4_direction = output ; comp2 out (OD)
pin_b2_direction=output ; RS232 TX

const bit usart_hw_serial = TRUE
const serial_hw_baudrate = 9600
include serial_hardware
serial_hw_init()

include print
include format

Procedure InitDeltaSigA2D() is
VRCON=0b11101100 --    0xEC
CMCON=0b00000110   -- 0x06 two common ref comps with outputs
end procedure

;
; Delta Sigma A2D
; The below contains a lot of nops and goto next instruction. These
; are necessary to ensure each pass through the Elop1 takes the same
; amount of , no the path through the code.
;
Procedure DeltaSigA2D() is
assembler
         LOCAL    elop1,comphigh,complow,eat2cycles,endelop1,eat5cycles,exit1
--DeltaSigA2D
        clrf counter1
        clrf counter2
        clrf result_l
        clrf result_h
        movlw 0x03 ; set up for 2 analog comparators with common reference
        movwf cmcon
elop1:
        btfsc c1out ; is comparator high or low?
--        btfsc cmcon,c1out ; is comparator high or low?
        goto complow ; go the low route
comphigh:
        nop ; necessary to timing even
        bcf porta,3 ; porta.3 = 0
        incfsz result_l,f ; bump counter
        goto eat2cycles ;
        incf result_h,f ;
        goto endelop1 ;
complow:
        bsf porta,3 ; comparator is low
        nop ; necessary to keep timing even
        goto eat2cycles ; same here
eat2cycles:
        goto endelop1 ; eat 2 more cycles
endelop1:
        incfsz counter1,f ; count this lap through the elop1.
        goto eat5cycles ;
        incf counter2,f ;
        movf counter2,w ;
        andlw 0x04 ; are we done? (we're done when bit2 of
--        btfsc status,_z ; the high order byte overflows to 1).
        btfsc Z --status,z ; the high order byte overflows to 1).
        goto elop1 ;
        goto exit1
eat5cycles:
        nop  -- this really seems to hate the goto $+1, keeps resetting. I am not so short of code space, case to be made to turn everything into nops
        nop
        --goto +1 ; more wasted time to keep the elop1s even
        nop ;
        goto elop1 ;
exit1:
        movlw 0x06 ; set up for 2 analog comparators with common reference
        movwf cmcon
end assembler
end procedure

function rescale(WORD IN value) RETURN WORD is
-- 1024 corresponds to 5V
-- multiply by 50000/1024 (~49)
var word temp =value*49
temp=temp/100 -- now lose excess precision
return temp

end function

InitDeltaSigA2D()

print_string(serial_hw_data,booted)

forever loop
DeltaSigA2D()
result=word(result_h)*256 + word(result_l) -- you must explicity make result_h a word as described on p11 of JAL manual
result=rescale(result)
format_word_dec(serial_hw_data, result, 3, 2)
serial_hw_data = " "
serial_hw_data = 13 -- CR
serial_hw_data = 10 -- LF
delay_1ms(500)   -- this is purely to allow the terminal display to catch up and not overload buffer of the slow device
end loop

Files

adc_test_16f628_v03.jal

and the hex file

adc_test_16f628_v03.hex

There’s a case to be made for using a voltage reference and setting it to be some convenient power of 2 like 2.05 V to save all the messy integer calculation in rescale

This is a video of the display on the serial port compared with a multimeter on the input, connected to a 5k pot between 0V and +5V. I should have moved the control a bit slower to allow the 0.5s sampling to catch up at times, but it shows it is reasonably accurate.

How to replace the volume control on an Audio Research SP8 preamplifier

I bought this preamplifier secondhand from Subjective Audio in 1984. My amplifer is a Mark 1, by the way, other models may be different.It has provided me with thirty years of listening pleasure, a good investment by my younger self. However, it is getting elderly and the volume control got scratchy. I shut it down for a few months while I mulled over my options. Remember this is a product that can ship out a signal of 60V, you don’t want a scratchy pot getting worse and sending 10V peaks into a power amp designed for 0.775Vrms full scale. You just don’t wanna go there…

This one can bite

Before you even think of reading further, note that opening the lid of this amplifer could easily kill you, not only is it mains powered but the rectified HT line operates at 630VDC. A high voltage DC shock is a totally different experience to a mains shock. If you have survived a mains shock you won’t necessarily survive a DC shock 😉 you have been warned. Here is ARC’s take on the matter:

Technical servicing of Audio Research vacuum-tube models should only be done by a trained audio electronic technician. Operating voltages inside these products can be lethal, and owners are advised against any tampering with internal components. Unauthorized modifications or circuit changes to Audio Research products immediately voids any protection under the terms of the 3-Year Limited Warranty.

I’m not just any old owner of an SP8. I learned electronics as a teenager in less litigious and more enterprising times picking junked tubed TVs out of skips and scavenging parts. Later on I worked as a broadcast engineer years ago and worked with high voltage TV cameras and monitors, before moving on into electronics design. If you have only worked on low voltage electronics then beware. Old stagers tended to work with one hand in their pocket because an electric shock across the chest is particularly bad for your health.

You have been warned. If you have any doubts then don’t do this. It is a lot easier to buy a new preamplifier than to buy a new life.

Now one option would be to return this to ARC in Minnesota, however, a glance at the T’s and C’s of their servicing indicates this isn’t likely to be a cheap option. The secondhand cost of an SP8 is about £650 these days, which sets the limiting case of what it’s worth to spend on one.

How to change the Audio Research SP8  volume control

The nice thing about this is that you can do this job from the top. Remove the screws holding the top lid, and save them carefully. They are some curious coarse American Imperial thread, fortunately the same as the sort that come on many PCs if you lose some.

First familiarise yourself with the patient. The circuit diagram is here,

Audio Research SP8 preamplifier circuit diagram (schematic)

You’ll observe a thin circuit board at the front, right on top. Your mission is to replace the volume control which is on the left hand side. First unplug the line stage valves, remember which are which. Indeed, get a digital camera and photograph where everything is before you dismantle it. Then unsolder the three wires that go to the line stage from the top control board.

unsolder these three wires to be able to lift the control board to replace the volume control of the Audio research SP8
unsolder these three wires to be able to lift the control board to replace the volume control of the Audio research SP8

 

These have stiff wire wound round the end, poked through a hole in the PCB. You can heat up the pad and lift from the top. I only realised life gets easier if you remove these after I had unsoldered the pot. It’s easier to unsolder these first, then remove the pot.

Remove the four knobs with an Allen key. remember being American, the ARC is gloriously unreconstructed imperial feet and inches, none of that cheese-eating surrender monkey metric hoo-hah here, so use an imperial Allen key set. Set the knobs aside, marvelling in their honest-to-God solid metal construction. Observe that there seem to be two diameters of shafts here, the pot shafts on volumegain and balance are slightly thinner than the switch shafts on source select and that odd mono/stereo/left/right thing which I’ve only ever seen on ARC gear.

Next get yourself a ½inch AF socket, or if you are careful, a ½” AF ring spanner, and unscrew the nuts holding the pots and two switches, plus the associated star washers. Set to one side. All the threads seemed to be the same despite the different shaft diameters.

Now very carefully move the board back and lift the volume control end. Remember that your amplifier, like mine, is likely to be very elderly, and being vacuum tube gear will have been thermally cycled zillions of times. That means the wires and plastic will be stiff and perhaps brittle. The last SP8 was produced in 1985. That means at least thirty years will have passed. Go easy on the old girl, right 😉

A solder sucker and a 25W or more temperature controlled soldering iron will be your friend. This is US gear, they don’t bother with all that namby-pamby Euro RoHS rubbish. They’re Real Men in Minnesota. You’re on fully leaded 60/40 tin/lead solder, like in the good old days, which makes life easier. Have at it, but note that more heat is required, this is not miniaturised SMD circuitry. A spot of WD-40 in your solder sucker to give it a good strong recoil and good suction will do the trick.

Audio Research SP8 Volume control
The offending part – the Audio Research SP8 Volume control (right) next to its replacement (left)

You’ll see I managed to snap off the tag from one section of the volume control, though I could have patched it if necessary. It is a 100k log-law (A-law or audio taper) part. ARC run the whole control section at a very high impedance, cascading the 100k linear balance control (presenting a 25k impedance to the volume pot assuming a low source) into the 100k log volume pot, which is then direct-coupled into the grid of V4.

Now you could replace this with a cheesy Chinese 100k log law pot, but bearing in mind you’ve probably got the same problem of being wrapped down at the low end of the travel, you will hate yourself all the time when one channel is louder than the other. So don’t do it. Spring for an ALPS high-end pot. This is your main control interface, you’ll use it every day, and a cheap pot will annoy you every day. I got mine from Tisbury Audio on ebay, look for ALPS Blue Velvet.

I got a 50k version. What’s that all about, I am replacing a 100k pot? Well, this is my chance to lose about 6dB of gain – by putting a 47k film resistor in series with the hot end of the pot I make it as if I have a 100k pot but never get to use the top half, thereby extending the bottom part of the travel which is where everything happens. I make the gain distribution of the SP8 a bit better suited to the modern world (I’ve already got the low-gain mod ARC recommend in Note 2 of the schematic), but without upsetting the circuit conditions. The balance control still feels as if it has a 100k pot after it, and to V4 it feels like there is a timid listener who never gasses the amp up past the halfway mark  on the original volume control (OK probably about 10 o’clock due to the log taper).

 

ARC SP8 preamplifier volume control post-mortem

ARC SP8 preamplifier volume control
ARC SP8 preamplifier volume control carbon track after 30 years

It was clearly old age that’s done for this. It was well made, with multiple tracks and multiple fingers covering the track. It might have been possible to clean this one up with switch cleaner, but in the end it’s got a lot of miles on it, and the carbon track just wears. A cheesy touch that honestly I wouldn’t have thought ARC would have done was the volume control has a stepped detent built in. There is no reason for this, indeed I was usually only on the first four detents and sometimes used the halfway positions. It isn’t a stepped attenuator and there’s no need for ARC to make out it is. However, they had to lubricate the detent mechanism; and this may have hastened the pot’s demise, as it was the first wafer that went scratchy. You can see a gunkiness on the slip-ring.

ARCs cheesy faux-stepped attenuator mech on the SP8 volume control
ARCs cheesy faux-stepped attenuator mech. And all that grease, oh my…

Over thirty years, that grease wants to move. It migrated to the shaft of the control, that was sticky and greasy when I removed the knob, and I suspected some of it eventually got onto the track. Even geniuses like ARC have bad days, and introducing a part than needed greasing and stopping me using every part of the volume control was a Bad Idea in my view.

The other trouble is the replacement is smaller, it has a different pin pitch, and the pins are in a different plane to the old one. This isn’t about to sit on the PCB as a drop-in replacement 😉 That’s a blessing in disguise, since there’s enough space to solder in some extensions to the pins and space to lose the 47k series resistors without modding the PCB in any way. Which would feel kinda rude.

First there’s some mechanical argy-bargy to sort. The ALPS pot has a anti-rotation pin. There’s no place for that to go on the SP8 chassis. Simple decision, do I drill the hole in the chassis of the SP8 or do I saw off the pin? I went for the saw off the pin option, funnily enough.

ARC SP8 replacement volume control
See that pin on the Blue Velvet? It’s gotta a go, because I’m not drilling my SP8. You can also see that the plane of the tags front to back and side to side is different between the old and new

The eagle-eyed will see there’s a great big slot in the Blue Velvet to avoid the tags shorting out on the front metal plate. That is where all the swarf is going to go from sawing the tag, because swarf is like that. So tape over the gap before you saw the pin off, okay. Otherwise you get to replace a scratchy old pot with a scratchy new one.

ALPS Replacement ARC SP8 volume control
Sellotape stops the swarf falling into the ALPS Blue Velvet giving me an instant scratchy new volume control

Next up was matching up the 47k series resistors. I want them the same, I don’t care about the exact value. They were nominally 2% but what the hell, it’s easier to check this before soldering them in. They both read 46.8k on my AVO M2007. Good enough for me.

ARC SP8 volume control replacement
matching the series resistors. The both read this, I won’t bore you with the second picture showing the same reading…

Observing the difference between old and new, I figured some extension wires would take out the slack, since the new control is smaller it would stand a little off the board. Obviously I no longer have the control to locate the left-hand side of the PCB, but I figure three other controls are good enough. So I wire some pins to the volume control and sleeved them. I sacrificed a couple of resistors for their leads which seemed about right for the holes in the Audio Research circuit board.

ALPS replacement SP8 volume control prepared with flying leads
ALPS replacement SP8 volume control prepared with flying leads
ALPS replacement SP8 volume control prepared with flying leads

Then it’s a case of carefully matching up pins and holes, pre-bending the wires to get the plane of the replacement to roughly match the old one. Don’t solder anything yet, just bend the outer leads over to stop it falling out into the guts of the amp.

ARC SP8 replacement control in board
ARC SP8 replacement volume control loose in board
ARC SP8 replacement volume control loose in board

Now it’s time to lower the board back into the amp and marry up the switches and pots with the holes. The new volume control has some play because of the unsoldered wires, to take up its rightful position in the front panel. Tighten up all the nuts, using the ½” AF socket for the three old controls and socket for a M9 nut for the ALPS pot. I used a 3/16ths W ring spanner, because it fitted.

Now everything is seated, solder the flying leads of the pot to the board, and wire back the ARC flying leads that go the the line stage input. Be very careful to make sure no bits fall into the amp, or if they do that they are extracted. Remember there is 630V B+ in there, looking to cause some trouble for someone… It was hard to get the camera in behind the installed pot to show it in service but this gives you the general idea

Installed replacement ARC SP8 volume control
Installed replacement ARC SP8 volume control
Installed replacement ARC SP8 volume control

Now double check everything, then power up the amp. I fed mine to a oscilloscope in parallel with some computer speakers. You don’t want to be down a preamplifier and the rest of your hi-fi if it all went horribly wrong. I fed a CD player into the back, and with some judicious manipulation of the unmarked switch shafts established that I had a working amplifier. On powering down the CD, I rotated the volume control and observed the absence of scratchiness. On the scope I was looking for any bursts of oscillation or general spuriae and bad attitude but there was none at any position of the volume control. I tested all the inputs and switch positions, and they all worked apart from the tape monitor input, where the switch had a low level on one side. I don’t use that so I can live with it, though I stuck a label on the monitor socket to remind myself should I ever want to use it. It would involve demounting the PCB on the switch panel and changing the switch, which I can’t match aesthetically. I’d have to change all the switches for diddy little ones.

It was now down to breaking out the IPA – that’s Isopropyl alchohol, not India Pale Ale, and cleaning some of the accumulated grime of the last 30 years from the recesses. Not the innards – in the end thirty years of thermal cycling means if it ain’t broke or in obvious distress don’t touch it, but it was time to clean my knobs.

a dirty knob or two
A dirty knob or two. Particularly the one on the left, where the grease from the detent of the pot worked its way out along the shaft, through the grub screw on the underside to gunk up the anodised finish
A dirty knob or two. Particularly the one on the left, where the grease from the detent of the pot worked its way out along the shaft, through the grub screw on the underside to gunk up the anodised finish

The IPA worked well, but couldn’t get more than about half of it off, and didn’t get into that groove. However the remarkable power of a cheap ultrasonic cleaning bath with some tepid water and washing-up liquid worked wonders.

Happiness is... an ultrasonically cleaned knob
Happiness is… an ultrasonically cleaned knob

Time to refit them, starting with the two switches on the right-hand side (which need the larger diameter inside for the slightly thicker shafts).

I didn’t want to change this pot, and indeed I first changed the tubes, in the hope I had a knackered tube. I didn’t, but they were due a change anyway, being over 10 years since I last did this. I got mine from Watford Valves. Overall the total job cost me about £110 for the new valves and pot, and about three hours of time.

The alternative would have been to get something like a Naim Audio NAC 172 XS. Eventually I will have to move away from the Transporter because I have just discovered that Logitech is end-of lifeing the whole Logitech Media server and players, and going to cloud. I am not having my hi-fi depend on anybody’s cloud 😉 Will I still be listening through this when I am 80? Probably not, but hell, hopefully it has a few more years in it yet.

The SP8 – a legacy from days before CD

Thirty years ago there were no CDs, good audio was to be had from vinyl LPs or not at all. It might have been different if Compact cassette hadn’t killed of reel-to-reel, but vinyl was where it was at. The SP8 is a legacy from vinyl days – records chucked out loads of out-of band signals and crud, you needed decent headroom to pass clicks and pops through the RIAA de-emphasis[ref]seems funny to write about the RIAA without cursing them, their lawyers, and the horse they rode in on, but they did a good job in the early days, standardising the frequency equalisation curves for LPs[/ref] without stretching them into dirty great thumps. The downside of the SP8 was it was noisy with low-output MC cartridges, but I used an AT1000T moving-coil transformer ahead of it which sorted that.

The SP8 served me well in my vinyl playing days, and it worked well with digital sources too, with one proviso.  The trouble with moving to digital is that line level took a big hike from the old 0.775Vrms[ref]Wikipedia claims domestic gear was lined up at -10dBV which is half that at 0.316 Vrms in which case it’s gone up by 12dB rather than 6. I don’t know if this is US-specific [/ref] to typically 2V p-p with the move to CD. The Naim CD-5XS has a line level of 2.1Vrms and the Transporter runs 2Vrms. And the trouble is the SP8 line stage is high gain – about 26dB, so I was always wound way down on the volume control, it would rarely get to 9 o’clock whereas in vinyl days I’d be happy at 11. This probably contributed to making it scratchy, as the first part of the track on the volume pot gets all the action.

I have tried patching the Transporter straight to the Naim power amp and using the digital volume control but it wasn’t that special. And up-down buttons as the main volume control user interface sucks. Whaddya do when you want to listen out for if it’s your phone or doorbell ringing?

The SP8 doesn’t owe me anything – thirty years of listening pleasure is a decent ROI on its capital cost. However, my hifi system is stable and well matched to itself and to me. Any change risks running into the Diderot effect so it was worth taking a flyer on fixing this.

The surprising repairability of old gear

Vintage gear is surprisingly repairable, because you get to replace component parts. It’s surprising that in three decades of progress people still haven’t come up with a better volume contro lthan the humble potentimeter, and these are still widely available. Whereas I’m not going to be fault-finding to component level on an iPod in thirty years time. or even still using it daily. However, an awful lot of portable audio like that is still repairable, because you most commonly get trouble with jacks, power supplies/batteries and cases. Most of these are to be found on ebay or are standard parts. I’ve serviced mobile phones and the like – case replacements in particular are an easy win, but I’ve replaced keys and joysticks before. However, portable gadgets aren’t going to be serviceable in the far future like this was, and nor are they liekely to be usable in the long term future.

For completeness’ sake, here is the rest fo the SP8 manual and parts list for the Mk1.

Continue reading “How to replace the volume control on an Audio Research SP8 preamplifier”

Fix for ratty behaviour of Wiznet 5200 with the OpenKontrol Gateway

I’m a fan of Ciseco’s OpenKontrol Gateway. It doesn’t get anywhere near enough love on their site compared to the flighty Eve. Where it scores is that it’s a cheap way of making stuff happen and I like that.

Ciseco OKG

It makes a dandy data logger, basically get the RTC kit and the SD card socket, slam one of their XRF radios in the left hand socket plus a LLAP thermistor device within 50 yards and you’re all set 🙂 You can add more thermistor devices while the datalogger is running and they get logged too without bumping it. And all for less than about £80 total system cost, what’s not to like? Okay in an ideal world the power consumption could come down a little bit as the OKG is in receive only mode, but it’s livable with – using 8 NiMH AAs gave me a couple of days runtime.

thermistor board with XRF

thermistor board in box

 

This saved our tail with finding out what the soil temperature was like in and outside a polytunnel earlier this year

reading of soil and air temp inside and outside polytunnel

What you can also see in the OKG picture is a Wiznet 5200 Ethernet card. What I didn’t realise is that this damn thing has a microcontroller inside. And it’s reset at the same time as the Arduino, so you get some sort of evil who-dares-wins race to get out of the starting blocks when that reset line goes High. The horse you want to win is the Arduino, so as the Wiznet’s ready to get initialised by the Arduino, but it doesn’t seem to happen that way.

Looks like with some configs the wiznet wins the race, and presumably gets confused when it sees data and stuff. I never got it to work reliably with the SD card datalogging. I the got another OKG, this time without the SD card and RTC option, just for posting LLAP devices from the XRF to Cosm. And this damn thing was about 50% reliable, it  gave me a world of hurt until I discovered this natty fix for this sucker over at Open EnergyMonitor. I am so grateful to them. Basically you dis the reset on the Wiznet and ground the sonofabitch once the Arduino powers up, so you know where it starts from rather than whatever it got to see on the data lines as everything Arduino and SD card and XRF and what have you fired up. Sounds good to me, and it works. I had considered chucking a monostable at this to ground the line for a sec so the Arduino can sort itself out, but caught the Wiznet getting its knickers in a twist after a while having started okay. So the option to deck it if it returns more than five -ve values for etherclient post is necessary. I went off pin 3 of the RH socket which is arduino pin 6 ISTR, but I need to see if there is a genuinely spare pin because one day I might want to use the OKG as an RF to RF gateway which would mean getting both slots into service. I’m open to pinching the red status LED if necessary 😉

The Wiznet seems actually reliable now, and if it does get itself stuffed in an IoT application returning a negative value for a post five times in a row I simply reset it and reinit the device. It’s not the end of the world if five temperature readings get lost, as long as recovery is possible 😉

You still have to patch the Arduino Ethernet library as per this wiznet blog to make it go.

Bad by design SMJ RFC2SC remote controlled mains sockets – fix

Maplin flog these SMJ remote controlled mains sockets.

SMJ Electrical remote and socket

The first thing you need to know about remote controlled mains sockets is make sure you get one which has separate on/off buttons. These things are ratty by nature, and some are a toggle – press the button to switch on, press again to switch off. That’s fine in a light switch, where you get to see if the light is on or off, but dire in a remote switch. The whole point of a remote controlled switch is you can’t necessatily see the remote item. A toggle is worse that useless in that case 😉 That’s why this is my second purchase of this sort of thing, these are made by SMJ electrical. I was using this to switch on the coffee machine in the kitchen in the morning. As the expensice 12V battery ran down the reliability of this got worse and worse.

I measured the battery and it was down to 10V. Putting the remote on a bench power supply showed it drew 5mA on transmit, and getting a scanner onto the job showed the frequency was 433.855 MHz.

This  was a little bit off the advertised frequency of 433.92 MHz on the  SMJ RFC2SC label, but a 65kHz discrepancy isn’t too bad. This falls within the 433.050-434.790 MHz ISM band

SMJ RFC2SC label says 433.92 MHz

So the first thing is to pop the lid of the remote and see what gives

Internal view showing PCB

The RF sub-board is a separate assembly, presumably to deal with various different regions’ RF allocations. It’s a pretty nasty piece of work compared to the rest of the remote, hand-soldered by the looks of it.

SMJ Electrical remote RF board showing really shoddy workmanship

Of note was that the hot side of the antenna is at the top. I had allocated button 1 to the coffee machine socket, and to press this you tend to put your hand round the top of the remote. I determined that this detuned the signal – it was easy enough to hear on the scanner that putting a hand round the back to press button 1 shifted the tone of the signal, and this was confirmed with a scope that the waveform was distorted. So a good tip for using these is to use the 4 buttons rather than the 1 buttons!

The next step was to test the range with the socket, which was poor initially. It wasn’t particularly sensitive to supply voltage, but it wasn’t particularly sensitive full stop. The claimed range of 50m was ridiculous, I fitted a lamp to the socket and moved to the room next door, and communication was lost. I adjusted the trimmer capacitor of the remote (on the other side of the board) and range improved dramatically.

Frequency 433.845 MHz

This now measured 433.845 MHz, which is still acceptably in the ISM band. It’s now 75kHz off. In an ideal world I’d have moved both the socket and the remote closer to the original frequency, but this will do and it’s still in band. It’s still on the original battery – the transmitter frequency isn’t particularly sensitive to voltage down to about 8V, but it was so marginal originally that the lower power must have pushed it over the edge. And I get coffee in the morning 😉

How to use the OpenKontrolGateway for Data Logging

The obvious place to look is this post, OpenKontrol Gateway as Data Logger from openmicros.org, which has some sample code, which didn’t work for me. It created the log file but didn’t write any data to it.

I hacked this to make it write the data

unixtime,day/month/year hour:minutes:seconds, LLAPmessage
1352219944,6/11/2012,16:39:4,ECTMPA7.866
1352219992,6/11/2012,16:39:52,EATMPA21.59
1352220052,6/11/2012,16:40:52,EBTMPA20.82

It’s also a bit more tricky to use, compared to a regular data logger. This is because the RF network is unsynchronised – the temperature nodes fire themselves up every 5 minutes, transmit a temperature reading and then go to sleep. This isn’t a polled system, and there may be other transactions on the network. The data logger simply logs all of these transactions, be they temperature readings, status readings or setting up devices – anything starting with an a is logged.

This is why I added the unix timestamp, so that it would be possible to plot these unsynchronised elements onto the same xy plot, with the timestamp along the x axis. Some data might want to be sampled more frequently than every 5 minutes, and some might be reactive, like a PIR sensor.

The receiving application has to pull all this stuff apart, first splitting the streams into the devices, using LEFT(LLAPmessage,3). This will always be aXY with XY being the deviceID

 

Modified program shown below

Continue reading “How to use the OpenKontrolGateway for Data Logging”

Remote sensing and the Internet of Things

Wires. That’s the problem with remote sensing, at least it has been until recently. You needed wire to get the signal back to where you wanted to view it, and often to power your sensor too. That’s a grand PITA. The last time I looked at this, about a decade ago, you could get little RF modules running at around 433MHz but these presented the raw demodulated FM signal. Great for voice but you then needed a modem to wrap around the project. And some sort of protocol stack, possibly.

That exchanged the signal wiring problem for a sensor powering issue, and these radio modules were send or receive so everything would end up fire and forget.

I was chuffed to find there’s been a lot of movement in this field. A lot of it seems Arduino based and I selected PICs when getting into micros, so it is a new learning curve. In researching this I came across JeeLabs and Ciseco. The latter had some £12 bidirectional RF to serial cards, the XRF, which I expected to attach a PIC. However, they seeme ot also have used the microcontroller on the RF board to do some signal conditioning for a few sensors, including temperature via the Dallas 18B20 or a thermistor. Since temperature and battery voltage/contact status are some of the things I want to remote sense that saves me a load of programming grunt-work.

They have also documented a simple serial sensor protocol, LLAP, which fitted my needs. The Internet of Things is all very well but if you need a TCP/IP stack for each battery powered node you need a lot of processing power and electrical power, which is back to wiring again.

So I ordered four XRF boards, a couple of thermistor boards and a XBBO carrier board to interface to an FTDI cable to USB. Assembling the thermistor boards and the XBBO were easy enough, now it was time to test it all out and getting some readings. To do that you have to set your LLAP sensor device to some particular address. and this is where is started getting hard. You have to program them over the air, and you have 100ms to respond to the started command.

Ciseco XBBO board for LLAP devices

That’s great for security, but I don’t type that fast 🙂 Which is why I use this script to do that job.