Category Archives: Electronics

Stuff about electronics

DK’Tronics Dual Port Joystick Interface

As part of my Z80 revival, I managed to get my hands on a DK’Tronics Dual Port Joystick Interface for my rubber-keyed ZX Spectrum 48k.

The interface provides two joystick ports, and according to Spectrum Computing, the left port implements the Kempston ( IN (31) ) protocol. The right port implements the Sinclair Port #1 protocol (keys 6,7,8,9,0) but there is a known error that UP/DOWN (keys 8 & 9) are reversed from the Sinclair standard.

https://spectrumcomputing.co.uk/entry/1000120/Hardware/DKTronics_Dual_Port_Joystick_Interface

Inside, there are a couple pf 74LS367AN’s (Hex 3-STATE Buffer/Bus Driver), a 74LS138BI (Decoder/Demultiplexer), 10 diodes, and a couple of resistors.

Interestingly there is no ZX Spectrum Expansion Port pass-thru, however the case does have a slot where one could be added.

The case is help together with three identical screws; two of which go through the PCB.

You can see from the underside of the PCB, only some of the connections are soldered. Presumably only those required, to reduce cost / manufacturing time.

Marking on the board include:

  • “JS3.1”
  • “dk’tronics”
  • “DA84” (presumably suggesting year of manufacture as 1984?), and
  • Some felt tip markings “T” and “23”, presumably from some QA processes

I’ve included a whole bunch of photos of the exterior, inside and both sides of the PCB.

ATmega32A Refused to ICSP

I purchased a couple of ATmega32A recently from eBay, in order to further develop the IO on the Z80 board. I made up a simple ICSP (In-Circuit Serial Programmer) board (see below) in order to program it using avrdude/Arduino.

Image

The problem was, however many times I tried to use avrdude to program it, it always came back with an error.

After much re-soldering, checking connections, swapping ICs, checking the usbasp programmer etc – I got my trusty EEPROM TL866II Plus programmer out, and did a full erase on the ATmega32A.

Image

Then it worked!!!

It turns out that there is a fuse (SPIEN) on the ATmega32A to disable serial program downloading! Once erased, this bit was cleared, and my ICSP circuit worked as expected.

I was able up burn the Arduino bootloder, Program via Programmer in Arduino, and subsequently see Serial output as my program ran.

Serial comms with Arduino using minicom for Linux

Whilst the Arduino Serial Monitor is good – I needed something that:

  • Would work in a Linux terminal (and hence I could use in VCScode)
  • Something that was bi-directional (as I wanted to take input from the keyboard)
  • Was easily available (i.e. I could apt-get install)

I started off using ‘screen’, but I felt this didn’t work well as it was difficult to navigate, and it would leave the serial connection hanging.

I can across ‘minicom‘ as a friendly serial communication program.

First, setup minicom, as you’ll want to turn Hardware flow control off:

sudo minicom -s

When I plug the Arduino in, it appears as /dev/ttyACM0, and I use 115200 baud:

minicom -c on -D /dev/ttyACM0 -b 115200

Ctrl-A x to exit – always handy to know, and the rest of the commands are:

Image

Ordering PCBs from China – Delivery Durations & Costs

I’ve ordered a few PCBs from China recently – and used various delivery methods, so I wanted to record their progress to give others (and to remind myself!) a sense of how long things take to arrive, and how much they cost

Having looked around, I use PCBWay for my PCBs, as they strike the right balance between quality, cost and delivery. I can generally be a little more relaxed about the delivery time, and the boards have always been excellent quality at a very good price.

The destination delivery point is a mainland address in the UK.

ProjectOrder DateDelivery MethodArrived @ HomeDurationPostage CostPCB Cost
Z80 v128/09/2020FedEx-IP7/10/20209 Days17 USD5 USD
Z80 v211/10/2020PCBWayExpress-IP29/10/202018 Days12 USD5 USD
Z80 v325/10/2020PCBWayExpress10/11/202016 Days10 USD5 USD

Image

ESP32 vs ESP8266

The Espressif platforms still remain a firm favourite of mine in terms of price point, ease of programming and functionality. I’ve been trialling the ESP32 as the new Central Heating controller over the winter (2017/2018) and have been experimenting more recently with using the smaller modules for solar-powered temperature monitoring nodes.

The ESP-01, ESP-07 and ESP-12 are all Ai-Thinker modules, based on the ESP8266 chip, and are easily programmable via the Arduino IDE (with the right Board and Library installed).

The ESP-01 remains a favourite as bare-bones WiFi IOT device where I/O isn’t important (just 2PGIO really) and you just need to collect some data and pass it somewhere else. The lack of regulator / LVO and USB connectivity also means there are fewer losses in the board itself – so it’s great for battery-powered/solar:

ImageImage

The ESP-07 has more I/O and also has the benefits of being a low-frills module – but the spacing of those pads is not 2.54mm – so it will require an adapter. It has the advantage of  U.FL antenna connector (as well as the onboard ceramic antenna) so you can put a better antenna in order to increase range.

Image

Image

The ESP-12 has more I/O again (11GPIO, 1ADC) and comes in a similar form factor to the ESP-07 (i.e. not breadboard friendly, albeit with more pads). Like all of the ESP modules listed here, it’s a 3-3.6V (i.e. 3V3) module.

Image Image

Note there are different versions within each module (i.e. ESP-01, ESP-01S, ESP-01M, ESP-07, ESP-07S, and ESP-12, ESP-12E, ESP-12F, ESP-12S) and these variants usually contain different amount of flash or have different options for onboard / ceramic / U.FL antennas. Something to watch out for!

Installing Packages from PPAs in Ubuntu

It’s no secret that the officially maintained repository for Ubuntu can get out of date quickly. A lot of software developers/houses are now letting you install applications straight from their repositories.

Ubuntu makes this possible with PPAs or “Personal Package Archives” (https://launchpad.net/ubuntu/+ppas).

So – how do you add a PPA to your system and then hence then add the application. Well, you can use the GUI method (https://askubuntu.com/questions/4983/what-are-ppas-and-how-do-i-use-them), or if you’re more like me – the command line version:

me@machine:~$ sudo add-apt-repository --yes ppa:js-reynaud/kicad-4
me@machine:~$ sudo apt update
me@machine:~$ sudo apt install kicad

Where “ppa:js-reynaud/kicad-4” is the name of the PPA, and “kicad” is the name of the package/application you wish to install. Hey presto – press”Y” where appropriate and it’s done!

Yes, if you’ve not already guessed, I’m installing KiCAD (http://kicad-pcb.org/) to try as an alternative to Eagle.

Getting Things Posted from Abroad

I’m acutely aware that I’m cheap. Many others, when getting things shipped from abroad (especially Asia), will use DHL-type services. Those big international names that can guarantee delivery across the globe in 3-4 days. But that comes at a price. Literally.

For example – from China to UK for an 850g (max weight) parcel (set of PCBs actually) will cost me:

  • $24 US (£19.04 GBP) if using DHL (may take 3-5 days)
  • $16 US (£12.69 GBP) if using HK Post (may take 15-30 days)
  • $12 US (£9.50 GBP) if using China Post Registered Air (may take 25-40 days)

So I’m patient. I’ve used HK Post twice and they have arrived without an issue. I’m just waiting on one via China Post.

Tracking

Tracking is important. It’s useful (and exciting!) to see how your stuff is transiting the globe – and does give you confidence that it will actually, eventually, turn up!

HK Post’s tracking system (http://www.hongkongpost.hk/en/mail_tracking/) is actually quite good.

China Post’s tracking service is a little more hidden and difficult to navigate (as a non-native speaker), but I’ve found this website serves me needs http://track-chinapost.com/ (yes, you will occasionally get “Server Busy”, but just retry again and it works).

For electronics components, I often use Thailand Post and their tracker is here: http://track.thailandpost.com/tracking/default.aspx?lang=en

Examples

  • PCBs from fab in China to UK, was “Delivery Ready” on 6/1/2017 10:58:06 PM, and delivered in the UK 10-06-2017 09:34 via HK Post – so around 9 days.
  • PCBs from fab in China to UK, was “Delivery Ready” on  5/29/2017 6:26:32 PM, and delivered in the UK 07-06-2017 12:02 via HK Post – so also 9 days.
  • PCBs from a fab in China to UK, was “Received” by China Post Group 2017-06-16 23:40:29, and I haven’t received it as yet. I think it has now landed in the UK (using tracker that happened 20/6), so that’ll be about 5 days and counting.

In conclusion, don’t be put off by the “my take up to 30 days” warnings that make you feel that you should go for a much more expensive service – if you’ve got the patience, and don’t need things immediately, it is often cheaper to wait a little longer. This is especially true when the components themselves are only a fraction ($5 US in some instances!) of the postage!

ESP8266 DeepSleep & Millis

While the ESP8266’s DeepSleep mode is useful for conserving power, one ‘feature’ of it is that it resets the module.

Yes, you can store things in the “RTC” (not really an RTC!) memory, as that survives the reset, I was curious to know whether millis() (the number of milliseconds since the program commenced) also survived.

Simple sketch:

/*
 Generic ESP8266 Module
 80MHz CPU
 40MHz Flash
 DIO
 115200 Upload speed
 512K (no SPIFFS)
 ck reset method
 Disabled debug port
*/
#include <ESP8266WiFi.h>
#define SECONDS_TO_MICROSECONDS 1000000
void setup() {
 // put your setup code here, to run once:
delay(200); // short delay here allows time for UART to align, otherwise you get gobbledy gook
 Serial.begin(74880);
while (!Serial) {
 ; // wait for serial port to connect. Needed for native USB
 }
Serial.print("First stop, millis: ");
Serial.println(millis());
ESP.deepSleep(60 * SECONDS_TO_MICROSECONDS, WAKE_RF_DEFAULT);
 delay(100); // apparently this is needed after deepSleep - not sure why?!
}
void loop() {
 // put your main code here, to run repeatedly:
}


The output looked something like this:

First stop, millis: 26259

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
First stop, millis: 478

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
First stop, millis: 455

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
First stop, millis: 453

If the second and third Serial.prints had been an increment of the first number then it would have suggested that millis() was fed by the RTC timer, and survived resets – but alas not. When you return from a DeepSleep it resets everything. As GPIO16 is tied to RST for this experiment, that also means that pressing RST would reset the millis() counter too – so it truly is milliseconds since the program commenced – not since the module was powered up.

That’s a real shame, as that means that when you come out of a sleep, you really need to make an NTP call (expensive power & CPU cycles & flash) if you need to know what the time/date is, rather than just doing it once and trusting the RTC time to carry things forward for you (albeit with temperature affected drift).

 

 

 

stm32duino “blue pill”

The typical Arduino setup is perfect for most of my projects. Atmel’s 328p in PDIP form factor is great for makers, and TQFP provides a smaller version is size is a factor.

However the 328p only has a certain amount of flash/program storage (32Kbytes), RAM (1Kbyte) and clocks at 20MHz max (although I usually use a 16MHz crystal).

In one of my projects, that controls the dimming of mains lights, I needed a microcontroller that could make split-second decisions at the zero-crossing point in order to control the sinusoidal AC waveform. Too much delay and the triggering point would be missed; leading to flashing and flickering lamps. Not good.

The typical 328p Arduino just wasn’t up to the task. I needed a different MCU. So I took the blue pill…

I invested in a STM32F103C board. Arduino compatible but more storage (64KB), more memory (20KB) and most importantly a faster clock speed (72MHz).

I got one of the boards very cheaply from Amazon (£2.49): HiLetgo STM32F103C8T6 ARM STM32 Minimum System Development Board Module For Arduino https://www.amazon.co.uk/dp/B01CZL6RGC/ref=cm_sw_r_cp_apa_kFWpzb1TH0BAR

I’m a fan of the Arduino framework, and didn’t want to use a complete new toolchain, development environment and framework, so I installed stm32duino in the Arduino IDE and just carried on as usual.

Full details are here: http://wiki.stm32duino.com/index.php?title=Blue_Pill

Why is it called the Blue Pill? It’s a blue coloured board… and that’s a reference to the Matrix where Neo has to make a choice.

Image

ESP8266 and Deep Sleep

Making the ESP8266 “run for years on a battery” is several makers’ dream.

The reality is it’s a hungry little monster, and no matter how many LiPo’s (or car batteries!) you put towards it, it’s still going to munch through them, eventually.

The ESP8266 however does have a “deep sleep” mode (and other power saving modes too, but this is the greatest) which turns the WiFi + system clock + CPU off = a considerable power saving.

I use the ‘Arduino Core for ESP866’ framework, and so it can be initiated with:

ESP.deepSleep(60000000); // 60 seconds

For some unknown reason, the parameter is in microseconds (not milliseconds like delay() or everything else!).

It needs a couple of things to get it to work:

  • GPIO16 needs to be connected to RESET (essentially the ESP8266 resets itself once the timeout has occurred. This, unfortunately, means that a GPIO line is out of bounds for other uses 😦
  • Because ‘waking up’ is the same as a reset, any values you want to keep must be stored not in RAM. So before you call it, use the onboard EEPROM, offboard memory, MQTT publish etc etc
  • If you want to connect, do something, sleep, and repeat – you may find that the loop() function becomes redundant and that the last thing your setup() routine does is initiate the deep sleep.

I’ve used it, and it works well. I’ve not gone to extent of measuring power consumption, but others have: https://openhomeautomation.net/esp8266-battery/