Sunday, March 05, 2017

LoRa with the LoRa Bee

For some time already LoRa is the new hype. This Long Range Low Power radio technology makes it possible to send small amounts of data over long distances using very little power. I's associated mainly with the LoRaWAN network and IOT applications, but LoRa itself is just the radio and the low-level protocol that is used to transmit and receive bytes. You could just use two transceivers to transfer data one to one, not using any network protocol or dedicated access points.

As I wanted to start experimenting with LoRa at lowest possible costs I bought a set of LoRa Bee modules from Dragino. At US$36 ( including shipping) for a set of two, it was the cheapest option at the time (Second half of 2016). That they also came with a neat antenna was definitely a plus.
But when it became time to actually connect them and send some data,I found this a little bit harder than expected.
First the 'Bee' form factor itself. Its got a 2 mm pitch header that will not fit a standard breadboard. And the pins are too small for standard female to male jumper wires.
Second it is 3.3V only. So I bought an Arduino Mini Pro, 8MHz - 3.3V version, and made some jumper wires from an IC socket and a standard header.
It's connected as follows: NSS-10, MOSI-11, MISO-12, SCK-13.

The WAZIUP LoRa Project


Next we need some software to drive it. And here it gets a bit harder. There are so many options, many extensively documented but usually in an experimental state. I found the article by Congduc Pham, 'A DIY low-cost LoRa gateway' to come closest to what I wanted to achieve. And it actually contains a lot of information on connections, theory and applications. Professor Pham developed a simple protocol for just transferring data from multiple end-points to  central server, without the overhead of the full LoRaWAN stack. All this as part of a 'WAZIUP' project that aims to bring this type of networking to sub-Saharan African countries.
By just following the instructions in the .pdf it's easy to install the program to the Arduino and get the software on the Raspberry pi.

A few pitfalls that I found while getting this all to work:


- The instructions tell you to clone the GIT repository . But GIT is not installed by default on  Raspbian. Use the following commands to get it :

$ sudo apt-get update
$ sudo apt-get install git-core

- Compiling the Lora Gateway software for Raspberry Pi B+. Since it is a B+, I compiled it for the the Raspberry Pi 2 , but later I found that my board is the original Raspberry Pi B+, which actually is a Raspberry 1. So if nothing happens after you start the lora_gateway, check your version.

- Minimal time between messages. I started with the 'Arduino_LoRa_temp' program, but I changed the time between messages on the Arduino to 1 minute  ( idlePeriodInMin = 1; ).  After a while I noticed that the gateway did not receive every message, but actually only one in two. It looks like the software limits the amount of transmitted bytes per hour. After increasing the interval to 2 minutes it worked fine. When using the 'Arduino_LoRa_InteractiveDevice' program I noticed that this has no limitations, and you can send multiple messages with short intervals. Officially there is a limit on the available radio time (Time On Air or ToA) of 1%, meaning you should not have actual transmissions for more than a total of 3.6 seconds per hour. This is explained in section 29 of the FAQ.


- The driver software is called SX1272.cpp, but I have a RF95 . The SX1272 is identical to the RF-95 as used on the Lora Bee.

- When the messages are received on the gateway, but the message itself is unreadable they ar probably AES encrypted, and the gateway does not decode this. For testing it's easier to disable AES. Just comment out the define:
//#define WITH_AES

- CAD = Channel Activity Detection.
- SIFS =  Short InterFrame Space

What it looks like on the RPi when it's running:

(And a minor issue, actually only related to the Rasperry Pi: SSH is now disabled on Raspbian. I could not connect through SSH to my Raspberry Pi running Raspbian Lite. An article on the RPi site explains that on newer version SSH is disabled by default. It also has the solution: just add a file 'ssh' to the root folder of the SD card. Make sure you change the password..)

What's really cool about the code is that mr. Pham made clever use of the ArduPi library so the code for the Raspberry Pi and the Arduino is (almost) identical.

LoraWan

When you want to go for a solution that is compatible with the LoraWan network, I suppose nothing beats the simplicity of the LoPy, an integrated module with Lora, WiFi and bluetooth, programmed in Pyton. There is a nice introduction on Element14.

Using LoraWan and the associated 'The Things Network' requires a nearby gateway. Which, if none is available, you can build yourself. At a total cost of about €200,- this is definitely not a bad deal. But if that's a little too much for just  some simple experiments you can also build a super cheap single channel gateway.

Tuesday, February 14, 2017

Recovery of a ZLinx ZP24D Radio Modem

The ZP24D-25RM is  a 2.4 Ghz radio modem by B&B Electronics, branded as 'Zlinx'. Although sold as Plug&Play, it comes with basic software that actually shows quite a lot of options.
And if you get some settings wrong (like the sleep mode) , it may become impossible to access the modem.
The standard software however does not have a solution for this. There is no way to revert to 'Factory Settings' without connecting to the modem in command mode, which is no longer possible because the settings are wrong. There is no reset button or switch setting to manually reset it, so you are stuck .

When opening the modem in search of a reset-switch, it was found however that the this unit is actually just a standard XBee module with additional interfacing electronics.

The XBee is a XBEE PRO S1, a fairly common module, which makes searching for a solution a little easier.



The following comes from the Digi website, ( http://knowledge.digi.com/articles/Knowledge_Base_Article/Recovery-procedure-for-XBees/?q=xbee+reset&l=en_US&fs=Search&pn=1 ) and disciusses ways to recover a 'sleeping Xbee:


A note regarding sleeping XBees:
If sleep mode has been enabled, the XBee may appear to be unresponsive since X-CTU expects the radio to be awake when performing any action on the radio. To see if the module is sleeping, go to the terminal tab and watch the Line Status indicator. If CTS periodically flashes, then the module is sleeping and only momentarily waking up.

Now this is exactly what has happened to my Zlinx. And they offer a solution, which almost works, except for a few issues.

First we will need the 'X-CTU' software, legacy version 5.2.8.6. :
 https://www.digi.com/support/productdetail?pid=3352&type=utilities
 (This was hard to find on the Digi website, but just Google it and the page will pop up.)


Then, if the X-CTU software connects to the unit, it will not recognize the module since it contains non-standard firmware.
To solve this, go to the folder where the ZLinx software is installed (E.G. C:\Windows\Program Files(x86)\B&B Electronics\ZLinx\ZlinxManager) There you'll find the folder 'Update' with the firmwares for the different types of Zlinx modems. Now copy all these folders to the 'update' folder in the folder where the X-CTU software is installed. (E.G. C:\Program Files (x86)\Digi\XCTU\update).

Now you can start the X-CTU software, select the right COM port and baud rate and then go to the 'Modem Configuration' tab. Select the modem type from the drop-down box:
FIRST click 'Show Defaults', so all settings are factory default. Then click 'Write'. The software will try to connect to the modem, and fail:
Now it's time to reset the XBee by switching power Off and On. The program will continue, and write the default settings to the XBee.

Saturday, July 02, 2016

The 'Makr-B-Bot' Part 2: Building the mechanics

After collecting the parts and studying the drawings and instructions of the Printrbot it's time to  start building. Before I got started I realized two things are very important for a 3D-Printer: It must be rigid, and all angles must be exactly 90 degrees. For lengths up to 30 cm the makerbeam seems rigid enough, although in the end I found that if you lift the bottom frame at one end it still deforms slightly. By using only the pre-cut length pieces I made sure all angles 90 degrees and all guides are exactly parallel .

This is the basic frame. Although over time many things have adde and modified, this part has remained basically unchanged.


Fixing the vertical rods,both at the bottom and at the top.
Mounted the Y-Axis stepper motor on a piece of Aluminium L-profile. A frame made from 4 pieces of 100 mm  is used as the carrier. Four ball bearings on the side, four on the front to carry the Y-Axis sliders.
The Y-Axis slider is assembled from two rods and some 100, 50 and 40 mm makerbeams. Note that on the photo's most parts are still assembled using Ty-Raps. Later on I replaced most of these with hose clamps, but during the build and test phase this is more flexible.
The print bed will be placed on a frame made from two rods and some 100mm makerbeam pieces. I mounted a piece of 40mm beam to the front of the steppermotor and two 10mm ball bearings to that. 

 The Z-Axis motor is placed in the corner, and fixed using one long hose-clamp.

Basic setup, with some electronics to test if all motors run and if it all moves as expected...




Sunday, May 01, 2016

Commodore VIC-20


The famous VIC-20. Predecessor to the Commodore 64, introduced in 1980 and thus being the very first affordable (US$300,-) colour computer.  Almost three million units were sold at the time, so they are still not very rare.
The unit I got (for €40,-) is in pretty good condition. The case has some inevitable yellow marks, caused by the reaction of UV light with the flame-retardand in the plastic. Something that could be removed (just google for 'RetrOBright')  but I think I'll just leave it like it is and not risk damaging the plastic.
The unit came without any cables, so the first step will be to find out how to connect the monitor. As always, this information is easy to be found. I found a complete overview on Retro Isle this time.
The video is on the 5-pin DIN plug, 2 = GND, 4= Video. 

Unfortunately it does not seem to work.
My small LCD monitor (that works fine with my TRS-80 and Acorn Electron) says 'no signal'. When measuring the video signal on the outside and on the board itself using an oscilloscope it looks good. But even adjusting the output level to the max does not solve the issue.
Just to be sure there is something wrong with it I connected it to the flatscreen television in the living room, only to find that it actually does work....
Looking into this issue I found several references to the fact that the video signal of the VIC is really bad, which did not really matter in those days since the standard television and monitor was pretty tolerant, but is a problem for our modern, all digital, LCD screens.
On the 'Denial WIKI' there are a few suggestions on how to improve video output which might be worth trying.


Monday, April 25, 2016

Acorn Electron

For only €20,- I purchased an Acorn Electron in excellent condition. The Electron was developed around 1982 as a direct competitor to the the Sinclair Spectrum, and even though it had some drawbacks it was sold in such large quantities that it is not to rare today. No need to tell the history, since there is already an excellent article on The Register about that.
Although this machine was not really on  my wish-list it's a pleasant surprise. First it's very compact and well-built. The housing is made of solid plastic, which even after 30 years does not show any colouring or scratches.
The keyboard is pretty good, and although most keys have multiple functions they are not crammed with it like the Commodore 64 or Sinclair spectrum.
The inside looks equally good. Just four screws have to be taken out to reveal a very clean motherboard and separate power supply .
  
They were very serious about the shielding against electromagnetic radiation, as clearly visible on the keyboard side.  

The user guide is excellent. It starts (as many user guides from this era) with an explanation of what a computer is: 

"A computer is a general purpose electronic machine that can be instructed to do a great variety of things - play games, perform complex calculations, store and retrieve information, display graphs and so on."
(You can read the whole guide on Acorn Electron World .  )

What surprised me is the possibilities of the Basic interpreter. It actually has named functions and procedures, a 'repeat..until' loop, quite advanced graphic functions and a built-in assembler to write machine code. And this machine code is definitely worth checking out, because the Basic is not really fast...

Enabling Colour on the composite video output

After working with it for while having it connected to a LCD monitor I noticed that it did not display colour. Initially worried that maybe the video circuit was damaged, I soon found out that this is intentional. The standard composite video output is set to black and white, but there is a link on the board that can be made to enable the colour signal. 
It's marked 'LK4', and I just soldered a link on it. After that the monitor shows colour as expected, but I do have the impression that the letters are less crisp (which was probably the reason for Acorn to have just black and white as a default)

Loading software

The machine came without a cassette recorder, but it should work with any standard audio recorder. Which in these days can be replaced by simple recording / replay software on a PC. I used Audacity to record a simple Basic program, and after fiddling a bit with the audio levels (for recording as well as playback) it worked fine.
Loading standard software appeared a bit harder. Almost all software published for the Electron is available online, usually in the '.UEF' ('Universal Emulator Format') file format. A very simple Windows program named FreeUEF can be used to either replay it as audio or to convert it to a  .WAV file that can be replayed by other software. The last solution did not really work for me. Replaying the created .WAV files using Audacity always gave an error after reading the first block. All other blocks seem to load fine, but the program will not run on the Electron.

Finally I used an Android App on my tablet named 'TapDancer'. This works flawlessly and because it actually looks like a Commodore Datasette it adds a little extra to the retro-feeling...

And if you want to go a step further, there is the GoSDC  expansion module that lets you load programs from an SD card. But let's face it: compared to loading programs using the tape interface it only saves you a minute during the loading itself. So unless you switch programs every 5 minutes I doubt if this is really worth it.


Tuesday, November 03, 2015

Go for C64 - Part II - The Arduino Leonardo solution

After trying to turn my C64  into a USB keyboard the whole project ended in a cupboard for a year at 90% completion. In the end the whole PICAXE - Arduino Pro Micro combination felt a bit clumsy.
Then I recently stumbled on a blogpost where someone connects a ZX81 keyboard to the Arduino Leonardo, and I found a cheap (€12,-) Leonardo-clone so I decided this was the way to go.

The board came with front headers, which makes connecting the keyboard super easy.
This is the C64 Keyboard matrix: ( diagram from the 'WaitingForFriday' blog)



Corrected C64 Keyboard matrix and keyboard connector diagrams
It is connected to the Arduino as follows:

A - D0
B - D1
C - D2
D - D3
E - D4
F - D5
G - D6
H - D7
0 - D8
1 - D9
2 - D10
3 - D11
4 - A0
5 - A1
6 - A2
7 - A3

The code can be a mix of the code from 'Biosrythm' and TechTonic . :

#include <Keyboard.h>

// ZX81 USB Keyboard for Leonardo
// (c) Dave Curran
// 2013-04-27

// Modified with Function keys by Tony Smith
// 2014-02-15
// Adapted for use with Commodore 64 Keyboard by Cees Meijer
// 2015-11-04
// Enable the debug mode (serial output) by keeping F7 pressed when 
// starting the program
// Special Commodore graphic characters are not implemented

#define NUM_ROWS 8
#define NUM_COLS 8

#define SHIFT_ROW 3
#define SHIFT_COL 1

#define RSHIFT_ROW 4
#define RSHIFT_COL 6

#define F7_ROW 7
#define F7_COL 7

#define DEBOUNCE_VALUE 100
#define REPEAT_DELAY 500

// Keymap for normal use

byte keyMap[NUM_ROWS][NUM_COLS] =
{
  {'1', '3', '5', '7', '9', '+', '$', KEY_BACKSPACE},
  {KEY_LEFT_ARROW, 'w', 'r', 'y', 'i', 'p', '*', KEY_RETURN},
  {'~', 'a', 'd', 'g', 'j', 'l', ';', KEY_LEFT_ARROW},
  {'~', 0  , 'x', 'v', 'n', ',', '/', KEY_UP_ARROW},
  {' ', 'z', 'c', 'b', 'm', '.', 0  , KEY_F1},
  {'~', 's', 'f', 'h', 'k',':', '=' , KEY_F3},
  {'q', 'e', 't', 'u', 'o', '@', KEY_UP_ARROW, KEY_F5},
  {'2', '4', '6', '8', '0', '-', '~', KEY_F7}
};

// Keymap if Shift is pressed

byte keyMapShifted[NUM_ROWS][NUM_COLS] =
{
  {'!', '#', '%', '\'', ')', '+', '$', KEY_BACKSPACE},
  {KEY_LEFT_ARROW, 'W', 'R', 'Y', 'I', 'P', '*', KEY_RETURN},
  {'~', 'A', 'D', 'G', 'J', 'L', ']', KEY_RIGHT_ARROW},
  {'~', 0  , 'X', 'V', 'N', '<', '?', KEY_DOWN_ARROW},
  {' ', 'Z', 'C', 'B', 'M', '>', 0  ,KEY_F2},
  {'~', 'S', 'F', 'H', 'K','[', '=', KEY_F4},
  {'Q', 'E', 'T', 'U', 'O', '@', KEY_UP_ARROW, KEY_F6},
  {'"', '$', '&', '(', '0', '-', '~', KEY_F8}
};
// Global Variables

int debounceCount[NUM_ROWS][NUM_COLS];
int altKeyFlag;
bool serial_output;

// Define the row and column pins

byte colPins[NUM_COLS] = {0,1,2 ,3 ,4 ,5 ,6 ,7}; // A,B,C,D,E,F,G,H
byte rowPins[NUM_ROWS] = {8,9,10,11,A0,A1,A2,A3};

// SETUP

void setup()
{
  // Set all pins as inputs and activate pull-ups
  serial_output = false;
  for (byte c = 0 ; c < NUM_COLS ; c++)
  {
    pinMode(colPins[c], INPUT);
    digitalWrite(colPins[c], HIGH);
    
    // Clear debounce counts
    
    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      debounceCount[r][c] = 0;
    }
  }
  
  // Set all pins as inputs
  
  for (byte r = 0 ; r < NUM_ROWS ; r++)
  {
    pinMode(rowPins[r], INPUT);
  }
  
  // Function key is NOT pressed
  
  altKeyFlag = ALT_KEY_OFF;
  pinMode(rowPins[F7_ROW], OUTPUT);
  if (digitalRead(colPins[F7_COL]) == LOW) serial_output = true;
  // Initialise the keyboard
  if (serial_output )
   {
    Serial.begin(9600);
   }
   else
   {
    Keyboard.begin();  
   }
}

// LOOP

void loop()
{
  bool shifted = false;
  bool r_shifted = false;
  bool keyPressed = false;
  
  // Check for the Shift key being pressed
  
  pinMode(rowPins[SHIFT_ROW], OUTPUT);
  if (digitalRead(colPins[SHIFT_COL]) == LOW) shifted = true;
  
  pinMode(rowPins[RSHIFT_ROW], OUTPUT);
  if (digitalRead(colPins[RSHIFT_COL]) == LOW) shifted = true;
  
    pinMode(rowPins[SHIFT_ROW], INPUT);
    pinMode(rowPins[RSHIFT_ROW], INPUT);
    
    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      // Run through the rows, turn them on
      
      pinMode(rowPins[r], OUTPUT);
      digitalWrite(rowPins[r], LOW);
      
      for (byte c = 0 ; c < NUM_COLS ; c++)
      { 
        if (digitalRead(colPins[c]) == LOW)
        {
          // Increase the debounce count
          
          debounceCount[r][c]++;
          
          // Has the switch been pressed continually for long enough?
          
          int count = debounceCount[r][c];
          if (count == DEBOUNCE_VALUE)
          {
            // First press
            
            keyPressed = true;
            pressKey(r, c, shifted);
          }
          else if (count > DEBOUNCE_VALUE)
          {
            // Check for repeats
            
            count -= DEBOUNCE_VALUE;
            if (count % REPEAT_DELAY == 0)
            {
              // Send repeat
              
              keyPressed = true;
              pressKey(r, c, shifted);
            }
          }
        }
        else
        {
          // Not pressed; reset debounce count
          
          debounceCount[r][c] = 0;
        }
      }
     
    // Turn the row back off
     
    pinMode(rowPins[r], INPUT);
    }
    digitalWrite(rowPins[RSHIFT_ROW], LOW);
    digitalWrite(rowPins[SHIFT_ROW], LOW);
  
}

void pressKey(byte r, byte c, bool shifted)
{  
  // Send the keypress
  if (serial_output) 
    { 
    Serial.print("|");Serial.print("\r\n");Serial.print("|"); 
    Serial.print(r);Serial.print(",");Serial.print(c);Serial.print(":");
    }
  byte key = shifted ? keyMapShifted[r][c] : keyMap[r][c];

  if (serial_output)
   {
   if (key > 0){ Serial.write(key);}
   }
   else
   {
   if (key > 0 ) Keyboard.write(key);
   }
  
}


Wednesday, May 06, 2015

The 'Makr-B-Bot' Part 1: Getting started

When the 3D-Printing hype started a few years ago with the RepRap and it's followers, I immediately considered building one. By that time however it was not really easy to collect the parts. People were building their own electronics, frames and extruders from scratch which included a lot of experimenting and tinkering to get it right. Round the same time I ran into a product called 'MakerBeam', an aluminium T-Slot profile for small constructions. This seemed like the right framework for a 3-D printer so I bought the starter kit. Bolted a few parts together and decided it would still be a lot of work to build a printer from this. So the kit ended up in a closet, and I have not used it since..
MakerBeam

In the following years the 3D printer market exploded, and at some point even got mainstream with little €1000,- plug and play printers you could buy at the supermarket. So I lost interest.  The idea of building one did stick at the back of my mind however. And over time I did collect some parts like a set of stepper motors, some extra Makerbeams and  some electronics.

Until recently I got inspired by pictures of the Printrbot Simple Maker kit . This amazingly simple design is probably the most minimalistic printer possible, yet it performs remarkably well for it's price, which is as low as US$350 for a complete kit. Now US$350,- is absolutely a good price for the full kit, but unfortunately that only works if you live in the USA. Once you get it to Europe the total price has become a whopping €550,- (= US$ 590,- !) which more or less defies the idea of a 'cheap DIY printer'. 

Since this is an 'open source' printer so it is possible to download the drawings and make the plywood parts yourself, but that would still be quite expensive for a single unit.
While looking for additional pictures of the PrintrBot design I also found the R360 Printer by Replicator warehouse :

This looks almost identical, but they chose a rotating bed to print on. That seemed a bit too experimental to me, although I understand it works pretty well. I do think it's a little bit too much plastic...

So I wondered if it would be possible to build this specific design using standard Makerbeam parts.

   
And I did not want to spend too much money on it so I spend quite some time to find the cheapest parts....

Parts.

  • Makerbeam starter kit.+ extra set of right angle brackets. ( €100 )
  • Acme rod (trapezoidal thread) with nut . ( €20 ). This one used to be hard to get, but nowadays most 3D printer shops sell the standard 30 cm version that is used in the RepRap Mendel  (MakeMendel,VanAllesEnMeer (Dutch) )
  • Flexible coupling 5 mm to 8 mm.n (€6,50) Any 3D printer shop has these in stock
  • 2 pcs Aluminium pully, T2.5 (€ 6,50)
  • 1 m. of T2.5 5mm Timing belt (€4,50)
  • 12 pcs.  LM8UU linear ball Bearings (€12,-) (€1,- / each is really good deal ! Kromhout Electronixs (Dutch))
  • 3 pcs. NEMA 17 stepper motors (€30,- (special package deal, might be hard to get them that cheap now..))
  • Funduino Mega 2560 R3 Module (Arduino Mega compatible board) (€15)
  • RAMPS 1.4 interface board (€18, including the Motor Drivers)
  • 4 pcs. 4988 Motor Driver (Polulu or compatible) 
  • Geeetech MK8 All Metal 3D Printer Extruder (DealExtreme) (€45)
  • AT Power supply (second hand, from an old PC)
  • Lots of Ty-Raps
  • 16 Hose clamps, 12-22 mm (€10)
  • 2 pcs. 1m. 8mm.  Steel Rod (€15)
  • Heated bed (€15)
  • 16x24 Photo frame (€1,50)
  • 12V/ 20 A Power Supply (€24,-)
Total: € 322,50
 (Actually a little less since not the whole MakerBeam kit is used)

Again, the US$350,- for the the PrintrBot Simple kit seems like a bargain. You probably have to buy all parts in really large quantities to get that low. Not to mention the US$179,- TIKO 3D , or the US$199 Genesis UNO  ..
And with the colourful DaVinci minimaker entering the local toy-shop, 3D printing definitely entered the realm of consumer goods.