Micro Python

 DIY, Electronics, Python  Comments Off on Micro Python
May 182014
 

Received my Micro Python board on the 12th of May which is a Kickstarter project I supported back in November last year, https://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers.

I just backed the project as I thought it was an interesting idea to use python in an embedded product.
So far I haven't had time to play around with it much, but I am really looking forward to it.

Here is the official web site for the project, http://micropython.org/.

board and box

One thing I noticed though upon starting the device up is that, at least on my Ubuntu machine, I did not get the pop-up window of the pyboard drive as described in the tutorial, if I have the SD-card inserted. If the SD-card is inserted, the only thing I get is the USB drive of that card. Without the SD-card inserted, I get the pyboard drive with the files mentioned. So I will go on without the card for now.

The tutorial, http://micropython.org/doc/tut-contents, is really nice and easy to follow.

To get a micro python prompt to write instructions directly to the board do,

screen /dev/ttyACM0

This is what you get from the help() function on micro python interpreter.

>>> help()         
Welcome to Micro Python!

For online help please visit http://micropython.org/help/.

Quick overview of commands for the board:
  pyb.info()    -- print some general information
  pyb.gc()      -- run the garbage collector
  pyb.delay(n)  -- wait for n milliseconds
  pyb.Switch()  -- create a switch object
                   Switch methods: (), callback(f)
  pyb.LED(n)    -- create an LED object for LED n (n=1,2,3,4)
                   LED methods: on(), off(), toggle(), intensity()
  pyb.Pin(pin)  -- get a pin, eg pyb.Pin('X1')
  pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
                   Pin methods: init(..), value([v]), high(), low()
  pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object
  pyb.ADC(pin)  -- make an analog object from a pin
                   ADC methods: read(), read_timed(buf, freq)
  pyb.DAC(port) -- make a DAC object
                   DAC methods: triangle(freq), write(n), write_timed(buf, freq)
  pyb.RTC()     -- make an RTC object; methods: datetime([val])
  pyb.rng()     -- get a 30-bit hardware random number
  pyb.Servo(n)  -- create Servo object for servo n (n=1,2,3,4)
                   Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])
  pyb.Accel()   -- create an Accelerometer object
                   Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()

Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name
Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD
Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN
Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)

Control commands:
  CTRL-A        -- on a blank line, enter raw REPL mode
  CTRL-B        -- on a blank line, enter normal REPL mode
  CTRL-C        -- interrupt a running program
  CTRL-D        -- on a blank line, do a soft reset of the board

For further help on a specific object, type help(obj)

To close the screen session do 'Ctrl + a' and 'Ctrl + d' in sequence.

As I said before, really looking forward to digging deeper into what I can do with this board.

Home Automation – RF Protocol, update.

 DIY, Electronics, Home Automation  Comments Off on Home Automation – RF Protocol, update.
May 012014
 

Since I wrote the posts on 'Home Automation RF Protocols for simple devices' back in 2012, I have received some questions and feedback, which I find very enjoyable. Unfortunately I have had to turn off the comment options, as I have also received a lot of spam. Still people who really want to, have managed to find my email address (in the 'About Me' page). Some of the questions was on devices which I haven't made the decoding of myself. This made me quite curious, so I went and bought some of these devices.

Now I have three different makers of simple devices, namely Proove from 'Kjell & Company', Anslut from 'Jula', and Nexa which is a wellknown brand not belonging to a special franchise but can be found almost anywhere.

Starting with the 'Anslut' devices, it is really similar to the Proove one when just looking at them. Here is a picture of the transmitters, with Proove to the left and Anslut to the right.

ProoveVsAnslutTransmitter

 

Opening the Anslut transmitter the PCB is also identical to Proove, but checking the IC, it was not the same as in my Proove transmitter.
This one was labeled,
TE89TP16N-
B932U0307#1
But after some searching on the internet it seems to be made by Holtek too.
I would imagine it is just another version of their '8-Bit OTP MCU with RF Transmitter' line-up of IC:s.
The Xtal is marked 13.560 MHz, which is 1/32nd of 433.92 MHz.

The pin-out of the IC is identical to the one on the Proove device

         -------
 Vcc  9-|       |-8 Vcc
     10-|       |-7
     11-|       |-6
 Vcc 12-|       |-5 SW4
 SW8 13-|       |-4 SW3
 SW7 14-|       |-3 SW2
 SW6 15-|       |-2 SW1
 SW5 16-|      o|-1 Dout
         -------

As everything is so similar between these devices, I strongly suspect the decoded data to also be very similar.
This time around I have a digital logic analyzer to decode the data transmitted on the Dout pin.

To my surprise I see a packet burst consisting of SIX packets, and not four as I saw last time. Of course this is most likely due to measurement tool limitations, as I used a USB oscilloscope last time, and it might not have had the bandwidth/capacity to capture all of the data. Anyway, this is what it looks like with the logic analyzer.

Anslut_SW1_Overview_DigiView

 

Zooming in a bit on the packet burst.

Anslut_SW1_Overview2_DigiView

Zooming in on one packet to decode bits.

Anslut_SW1_Packet_DigiView

Defining the pulses.
High 250 us, low about 2750 us  -> Sync
High 250 us, low about 1500 us. -> Zero (0)
High 250 us, low 250 us. -> One (1)
Last bit.
High 250 us, low 10500 us. -> Pause
A packet consist of, Sync + Data + Pause.

Decoding 'Data part' of a packet.

Bit
0        10        20        30        40        50           60
1234567890123456789012345678901234567890123456789012 34 56 7890 1234
--------------------------------------------------------------------
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT GG OO DDDD NNNN

Bits #01-52 -> TxCode (T)
Bits #53-54 -> Group (G)
Bits #55-56 -> On/Off (O)
Bits #57-60 -> ? Dimming/Channel ? (D)
Bits #61-64 -> Device Nbr (N)

As every other bit sent over the air is redundant, it is the inverse of the previous bit, the packet consist of 32 logical bits

Going back to my Proove tranmitter, and hooking it up to the digital logic analyzer, it also shows a packet burst consisting of six packets. All of the decoding is the same as for the Anslut device.
Defining the pulses.
High 250 us, low about 2500 us  -> Sync
High 250 us, low about 1250 us. -> Zero (0)
High 250 us, low 250 us. -> One (1)
High 250 us, low 10000 us. -> Pause

Time to check the Nexa device. Note this is the simple version, and cheap, of their devices.

First I open up the transmitter, and can immediately see that it is completely different to the other ones.

DSC_0310

This is how the other side of the pcb looks like.

DSC_0312

The component on the frontside marked 'H R4334' at position SAW101, is a SAW filter with three pins.
1 - Input
2 - Output
3 - GND

Debuging the IC, which has no markings on it, on the backside gives.

     ________
 5 -|        |- 4 
 6 -|        |- 3 
 7 -|        |- 2 
 8 -|       o|- 1
     --------	

Using the oscilloscope to have a look at the signals.	 
Pin:
1 - 3.8 V
2 - Dout, Pulse train when pressing button
3 - 
4 - 3.8 V noisy
5 - < 1 V rippled
6 - same as 5
7 - same as 5
8 - GND

So, we seem to have a Dout pin here too. Time to hook up that analyzer again.

This is what a packet burst looks like. Note, only five packets in the burst.
Nexa_on1_Overview_DigiView

Zooming in a bit on that burst.

Nexa_On1_Overview2_DigiView

Finally here is how a packet looks like.

Nexa_On1_Packet_DigiView

Data part time decoded:
High 250 us, low 2750 us -> Sync
High 250 us, low 250 us -> one
High 250 us, low 1250 us -> zero
High 250 us, low 10000 us -> Pause

This is exactly the same as the Proove device timing, and as expected the data part of the packet is also the same as the Anslut and Proove devices.

With this new knowledge, I have decided to update/change my 'Home Automation, RF Protocols' page to reflect my new findings, and to only have device data which I have decoded myself.

I have also updated the Arduino library that I made some years ago. Since there are some differencies between Proove/Anslut and Nexa, such as the channel code and the way to number unit 1 to 3, I made two librabries: Proove/Anslut and Nexa.

Branching strategy

 Git, Software  Comments Off on Branching strategy
May 012014
 

This is my branching strategy, which should work well for any development from a single developer to a small team.
The goal for the strategy is to minimize branching, and administrative tasks.
For large team development a completetly different approach is needed.

Here is the strategy described in words:
* Use Master branch as development branch.
* When it is time for a release,
- tag the commit, ex v1.0
- create a branch, ex v1.0
* Continue development on Master branch
* Make corrections/fixes for v1.0 release on branch 1.0
* Merge fixes back to development/master branch (if needed)

Some ascii art to show the workflow

 tag     1.0                             1.1
 ---------*------------------*------------*------------------*-------> Master
           \                /              \                /
            \              /                \ v1.1         /v1.1.1
             \ v1.0       / v1.0.1           -------------*------> 1.1
              -----------*-------> 1.0

Here is a small example

git init
echo "some text" > a.txt
git add a.txt
git commit
echo "some more text" > a.txt
git commit -a
git tag -a v1.0 -m 'version 1.0'
git branch v1.0
git checkout v1.0
echo "third row of text, on new branch" > a.txt
git commit -a
git checkout master
echo "third row of text on master branch" > a.txt
git commit -a
git merge 681d9911379f4bed16903c876b72243e3de7d4dd
git log --graph --pretty=oneline --abbrev-commit

The resulting git tree.

* 0ffb123 Merge commit '681d9911379f4bed16903c876b72243e3de7d4dd'
|\
| * 681d991 Text added on v1.0 branch
* | 5c8800b Third row of text on master branch
|/
* 0496fc8 Added a second row of text to a.txt
* f5251a8 Initial commit, adding file a.txt