Sunday, 15 January 2017

Getting to Blinky - With a STM32 "Blue Pill" devboard

For the newbie embedded developer, the Arduino ecosystem is the perfect place to start. It's really easy to get up and running with a new development board. All you have to do is buy one of the branded boards, like an Arduino/Genuino Uno, download and install the single software package, then run the IDE. All the required drivers are installed and the interface, while fairly spartan, is easy to use. Just select the board type and load one of the example pieces of code.

The popularity of the Arduino ecosystem of software and dev board hardware, along with its open source heart, has meant that a range of clones or compatible products are also available. This means that you can buy a really cheap development board from places like eBay or AliExpress. Even though Arduino hardware started with 8 Bit Atmel ATMega microcontrollers, they have now evolved to include a range of modern 32 bit microcontrollers, like the Atmel (now Microchip) SAMD21 in the Arduino Zero. Others have adapted the Arduino IDE to be used with a variety of hardware, like the really cheap WiFi chip ESP8266. This proved very popular with tinkerers the world over, so much so that the newer version of the Arduino software included support to be able to run code directly on these little modules. This required someone to adapt the Arduino bootloader to the chip. The "bootloader" is a little piece of code that runs when the device first boots up, providing a mechanism for people to load custom code onto the chip using a simple serial protocol.

One of the simplest and smallest 8-bit Arduino modules is the Pro Mini. It requires an external USB to UART adapter in order to program it. Sparkfun Electronics designed it as a module to be included in electronics projects. It's only $10USD, although it's more like $20AUD by the time it gets here. plus you need the USB to UART adapter, which at $15USD costs more than the dev board itself!! So even trying to do it cheaply, here in Australia you're looking at something around $40, which is about the cost of the UNO board that includes the communication IC.

I use the 3.3V version of the Pro Mini in several projects, because many (most) sensors these days only speak at a 3.3v level. If you use the usual 5V Arduino, you need things like "level shifters" to make sure the voltage level of the signalling circuit doesn't fry the expensive sensor. Instead of spending alot of cash mucking around with the brand name boards, you can buy cheap clones of these from Aliexpress, so it's really easy to leave these inside whatever project you're making, and not worry if it gets zapped or blown up. Sure, there are some issues using these instead of the proper branded ones, but sometimes cash is king. The lowest cost often wins!

 But how cheap? Try around $2 a piece!

But what if you need something more powerful, like one of these 32 bit Arduinos? The Arduino branded ones with the 32bit microcontroller still cost around the same as the 8-bit ones, but most of them incorporate a USB interface on the chip, removing the need to have any external programming board. So what cheap 32 bit option is there?

It turns out that there aren't many clones of 32 bit Arduino devices. But China does have an equivalent to the Pro Mini. It's often called a "STM32 Minimum System Development Board", or a "Red Pill" or "Blue Pill" depending on the PCB colour. It uses a STM32F103 microcontroller, and has a breadboard friendly form factor. I first read about it on the CNX Software blog . It can be loaded with a modified bootloader so that it can be programmed using the Arduino IDE. Given the cost was so low, I thought I'd buy one and have a tinker. Proper embedded developers use a hardware debug tool to program similar hardware, so I bought a cheap one of these to match. I didn't know if I'd need it, but I figured it was cheap enough to have on hand if I ever needed it.
STM32F103 Blue Pill board and ST-LINK V2 debug tool

Enough of the background story. I ended up trying a few things before I finally managed to get the onboard LED to obey my flashing commands!!! Here's a summary of the process.

  1. Download and install the latest Arduino IDE. Currently 
  2. Turns out that the ST-LINK V2 dongle IS useful. Rather than just install the drivers for it that can be sourced from the ST website, download the entire "ST-LINK Utility", which includes the driver AND relevant application. Run the installer and follow the prompts.
  3. Download the STM32-duino bootloader repository. Save and extract it to a temporary location. Thanks to Roger Clarke for making the mods to suit the STM32F103 boards!
  4. I probably did this step wrong, but in the end it seemed to work. The instructions for this step are here. Roger Clarke has another Github repo for all the board hardware files, so that the STM32F103 and others can work with the Arduino IDE. Follow the instructions and download and extract the repo into the correct location. If this doesn't work, and you have the latest version of Arduino with the "Boards Manager", instead of downloading the repo,  just add "" as an additional boards manager url in the IDE preferences. Restart the IDE, then go to the Boards Manager (Tools > Board:xxxx > Boards Manager). Scroll to the bottom of the list and you should find the one labelled "STM32F1XX/GD32F1XX boards by stm32duino". Click the name, then click the Install button that appears. Wait for it to download and install, then restart the IDE for good measure.
At this point, you should be able to select the "Generic STM32F103C series board, then select the "STM32F103C8 (20k RAM. 64k Flash)" variant, and the CPU speed of 72Mhz. You then need to connect the ST-LINK V2 to the dev board. The end connectors opposite the Micro-USB socket are the ones to connect. From top to bottom, the pins are labelled "GND, SWCLK, SWDIO, and 3.3". On mine, the SW is hidden by the pin header.

Connect these to the corresponding 4 pins on the bottom row of the ST-LINK tool. The case shows the pinout. Make sure you plug the power into 3.3V, not the 5V pin. You can then plug the ST-LINK into your computers USB port. Back in the Arduino IDE, in the "Tools" menu, choose "SWD" as the upload method. Now you can write some code, or choose one of the examples in the "Generic STM32F103 series" section.

In my case, the onboard LED is marked as being connected to the pin PC13. I used this name as the reference in the Blink example, and voila!!! Flashing LED.

Now if you don't want to use the ST-LINK, and just want to use the onboard Micro-USB port, then you'll need to install the bootloader. First, make sure the dev board is wired up to the ST-LINK as before. On your computer, run the "STM32 ST-LINK utility". Click "Target" then "Connect". Information should appear in the "Device" area at the top right of the window - like this:

Then click File > Open File, and navigate to the extracted bootloader files you downloaded at step 3. Navigate into the folder named "binaries", and find the file named "generic_boot20_pc13.bin". This is because the LED is on PC13!! Then click "Target" then "Program". In the next window, ensure the 
start address is "0x08000000", then click "Start". Wait about 4 seconds til it's finished, then you're almost there. The last step is to install the DFU utilities that were part of the download in step 4. Inside the extracted ZIP of the Github repo, navigate to "\Arduino_STM32\tools\win\dfu-util-0.9-win64\" folder, and run the "dfu-util.exe" program. This will install the drivers for the "Maple Serial" device, and the DFU driver. DFU means "Device Firmware Update". It's a mode where firmware can be loaded from an external source. 

Now in the Arduino IDE, you need to select the upload method of "STM32duino bootloader". Write some more code, then click upload......and nothing happens!! But it says "Done Uploading" ???
With this board, you need to press the reset button just after the IDE shows that it is uploading, otherwise the process will timeout and fail. Try uploading again, and press reset at the right time.

Well done! You've got to Blinky 2 ways - via SWD and via the STM32duino bootloader!

Sunday, 7 February 2016

#SocialSpaceWA - ESA's First Western Australian SocialSpace event!


When you hear "European Space Agency Deep Space Tracking Station," it's understandable that the first thing you think of is that it's somewhere in Europe. While there is a station located in Europe, the ESA actually has two other deep space antennas equally spaced around the world as part of their Estrack network. Estrack is a global system of ground stations providing links between satellites in orbit and ESOC, the European Space Operations Centre, Darmstadt, Germany.

 Deep Space Antenna 1 (DSA 1) is located in New Norcia, Western Australia. It was commissioned in 2002 and was the first antenna in ESA's Deep Space Network, which was designed to give the ESA an independent  capability to communicate and control deep space missions. It is a huge 35m diameter parabolic dish, with the capability to communicate beyond Mars. The first signals received by this station were from the NASA Stardust mission in June 2002.
DSA 2 is located 77 kms west of Madrid, Spain, at a place called Cebreros. Like DSA 1, the dish in Spain is a 35m diameter. It is separated from DSA 1 by 120 degrees of longitude, and was first commissioned in 2005
DSA 3 is another 120 degrees around the globe, at Malarg├╝e, Argentina. It began operation in 2012.

The three Deep Space Antennas complement the NASA Deep Space Network, giving a combined total of 6 stations. Three in the Northern Hemisphere, and 3 in the Southern Hemisphere.

Estrack have a number of other resources in Western Australia. Up until 2015, there was a station located on the outskirts of the state capital - Perth. This was used to communicate to satellites in Low Earth Orbit, as well as other spacecraft during their Launch and Early Orbit Phase (LEOP). This station was recently decommissioned, with the functionality taken over by a new 4.5m dish out at New Norcia - 120km away. Which is the reason for this blog post!!! ( Finally....)


Only a few weeks ago, I saw that ESA had put word out via their @social4space Twitter account, that they were going to host an event on 10th and 11th Feb for the inauguration of the new 4.5M dish. It would be a behind the scenes look at one of the few space related facilities here in Australia, and it's in my backyard (not literally!) The event was by invitation only, and people with social media "credentials" could apply to be selected for the event. Now if any of you are as much of a space nerd as I am, then this is one opportunity that wasn't going to be missed! I completed the application process and waited for the announcement of the successful attendees......

YESSSS!!!!! I was invited!!!!!

Myself and about 14 other space geeks are going!! We're going to have an awesome time!
The event will be a mix of socialising, presentations by astronomers, and a behind the scenes look at the facility. 

For updates on the event, follow the various social media accounts of the participants here,  ESAs @Social4Space account on Twitter and the ESA Facebook page. For official event images, there's a Flickr album

I'll post updates via a mix of this blog, the @OzQube1 Twitter Account, the OzQube-1 Facebook page and my personal @ssshocker Twitter account. 

More soon!!!!

Thursday, 21 January 2016

Podcast Caller

One of the podcasts that I listen to is "The Amp Hour". If you haven't heard of it, its a weekly show that discusses electronic design, amongst other things. One host, Chris, is based in Cleveland USA, while the other, Dave, is in Sydney, Australia.
For the show that was "aired" ( Uploaded?) on January 8 2016, Dave was still having holidays, so the show was a crossover show with another podcast that I listen to - "Embedded.FM". Elecia and Chris from Embedded.FM, and Chris from The Amp Hour hosted the show and asked for people to call in with questions relating to electronics or embedded hardware or software.

As I've traded tweets with the hosts, I thought I'd step it up and call in to the show!! I thought I'd ask a question about watchdog timers - what are the pros and cons of internal vs external watchdogs?

Listen to the show here:

It turned out that 4 out of 5 callers were from Australia! So we definitely made up for the Australian host being away!

Wednesday, 12 August 2015

Getting Started with a Space Project

This is a blog post I wrote for the STEMN website

How The OzQube-1 Project Began


When you see all the awesome projects on the Internet, social media or even the news, you get caught up in the amazement and wonder of what the project is or has achieved. People sometimes forget that they all had to start somewhere. They were all just an idea in someone's mind, and at some point, that idea needed to emerge into the physical world. I wanted to share the background of my project with the STEMN community, and to give readers some tips on getting started.
In case you're not familiar with my project, it's called "OzQube-1" . It's a tiny PocketQubesatellite that I'm building it in my back shed. Although to be fair, just the development and assembly of the prototype has been in the back shed! Its mission is to capture images of Australia from space, and transmit those images back down to earth to anyone that wants to listen. It's made news on ABC Radio here in Australia, one of the leading Science news websites Phys.Org , and even a prime time Current Affairs TV show - Today Tonight .
But how did I get started? Why did I decide to do this particular project? Lets go back a few years.....
If you're reading this, then I'm probably safe to assume that you've heard of the Mars Science Laboratory, also known as "Curiosity." It was the first space mission that I'd really taken an interest in. I couldn't tell you exactly when I got that space bug, but the it was somewhere between the launch and when it landed on Mars, a little over 3 years ago in August 2012. By the time Curiosity had landed, I was well and truly on my way to being a space nerd. I had become so excited about things that I even got my colleagues at work to watch the live stream for the landing! Following that event, one of my colleagues would regularly ask me "How's your mate on Mars?", at which point I'd update him on the latest images or discoveries. 
Not content with one space mission, I subscribed to a popular internet forum that deals with all things space, to get my fix of information for missions both old and new. The Internet has made information on all types of space missions much more accessible, yet many of the hands-on details and know-how surrounding these missions still remained  locked up by government agencies, under the belief that the transfer of knowledge relating to satellite systems needed to be regulated just like the trafficking of arms. One area, however, contained an abundance of reference material - Cubesats. By 2013, the Cubesats had been in orbit for more than 10 years. Various Universities (Colleges), companies and government organisations had launched a number of satellites based on the Cubesat form factor, specifically for research and scientific benefits. This has resulted in a large number of papers and theses being written, detailing the cubesat subsystems, operational performance and mission details. This was a goldmine for a space information junkie like myself! But at this point, I was not considering starting a project of my own.
In late July 2013, a company called Planetary Resources started a Kickstarter campaign to fund a space telescope that would be publicly accessible, and have a second camera and a screen onboard. The screen would be used to display a selfie that people uploaded via the web, and the second camera would capture an image of  the earth with their image in the foreground. Here was a company that really wanted people to get involved in space exploration, so I became a supporter of the campaign, and began to follow their progress.
Not long after the Planetary Resources Kickstarter, another space related campaign started. This one had an interesting title - "Want to build a satellite but dont have a NASA sized budget?". The campaign was part of the launch of a new online store that supplied structures for a new type of satellite called a "PocketQube". This was the first time I had heard of a PocketQube. Even though these satellites were designed to be more affordable that Cubesats, the structures on offer as part of the campaign were still something that you'd only consider if you were serious about building a satellite. They're not something that you'd buy just for interests sake (they were about $500AUD). But the potential for the electronics inside it was something that appealed to me. Not only had I been getting obsessed with space, I'd started to listen to a podcast called "The Amp Hour" during my daily commute, and was keen to learn about how to use electronics design tools to make custom circuit boards. Still, a satellite seemed a bit too complex. I had recently made my first RC quad-copter, and was thinking about giving the controller an upgrade with GPS etc, ready to turn it into a proper drone.
Very soon after the PocketQube Shop campaign, the first 4 PocketQube satellites werelaunched into orbit. One of the PocketQubes was called $50Sat. It was designed and built with the name in mind, although I found out subsequently that the cost to make it was more like $250. It used commodity components and it took advantage of low cost electronic prototyping. The creators of the satellite had made a lot of the details of their project available on the internet, so I learnt that it was fairly easy to listen to the telemetry being transmitted. I ended up buying the required equipment, which was one of those USB TV tuner dongles, along with a modest antenna and a cable or 2. I was then able to receive the telemetry from this satellite while sitting in my lounge room (My wife thinks I look quite amusing waving an antenna around in the air, waiting to hear the alien sounding transmissions.) But still, I wasn't thinking about making my own satellite
I kept in touch with the person behind the PocketQube Shop - Tom Walkinshaw. We traded emails and discussed things like the need for a standardized circuit board and backplane connector to make up the stack inside the PocketQubes. He put me in touch with a group of enthusiasts around the world, and together we managed to arrive at some kind of consensus - the PQ60 standard. Throughout this process, I really wanted to keep the hobbyist - i.e. myself - in mind so that the specifications wouldn't  exceed the skill level or affordability that comes with doing things at the hobbyist level. I had started to use some EDA tools (like Eagle) to make sure I could route the traces on the circuit board to and from the main connector. 
It was around this time that I had come to the realization that I believed that I could build myself a satellite. All I needed to do was work out exactly what to put in it, how to get it all working together, then actually build it..... Sounds simple!

How to get started

So we're finally at the point where I stopped just thinking about making a satellite. It was time to start creating something. It was time to start the project. Little did I realise that I had already started. Here are my steps or tips to starting a space project.

The first step to getting started is passion. Passion is the thing that inspired you in the first place, and it is the thing that keeps you going. It drives you to learn about things that you haven't done before, and to pick up the pieces when you make mistakes. There are often other motivations for doing a space project, but to stick with it and see it through, you have to be passionate.

What happens next? I know this is going to sound pretty out there, but the next step is to actually start.... It's time to take all those thoughts that have been swirling round your head and get them out into some kind of coordinated order. You've heard of "back of the envelope" calculations? Well, put them onto a proper piece of paper! (or spreadsheet.....unless you're old school!) Create yourself a high level concept and work out the key components. See if you can create a single page summary of the project. You don't need to know all the details yet, you just need to understand what the aim of the project is and what is it going to do. 
From this point, you should be able to break down the project into smaller chunks. Think of  your main project as a collection of smaller projects, each one with a specific purpose. This is where you start looking at the resources that you have, have access to, or need to obtain. What parts are you able to complete yourself? Who are your team members? What skills can they contribute? It's around this point where you do the old feasibility analysis. Based on all the information you've gathered and the breakdown you've worked out, is the project achievable? Do you need to just focus on some of the smaller projects? Sometimes, the smaller projects are just as important in their own right. It would be better to complete a smaller project than have an unfinished bigger one.
Once you've got your long list of smaller projects, it's time to start getting into the nitty gritty and start the technical side of things. You know - hard facts and numbers, creating technical designs and making actual hardware. That sort of thing. Its up to you how this part is managed. Big projects may need proper Project Management. Small ones may just be worked on in your spare time. That's up to you, and that's well past the scope of this blog post!


If the above was a little long-winded, here's a short summary for you to end on.
  • You've got to want to do something (you wouldn't be reading this if you didnt!) 
  • Be passionate about the project. Know what you want to achieve.
  • Get the high level plans onto paper, or computer. Summarize the project.
  • Break it down into smaller, manageable chunks.
  • Start something amazing!
  • I hope that this post helps at least one of you out there. It may not work for all of you, but it is how I see things through what I've experienced creating my own space project. Please leave me feedback in the comments, and follow my project here on STEMN, or on Twitter andFacebook . If you want to help get my project into space, please consider donating via myGoFundMe campaign

    Wednesday, 17 June 2015

    Backyard Shed In the Media

    After presenting at the Australian Cubesat Workshop in April, the news about OzQube-1 had started to spread! It was picked up on by a local journalist who made contact with me. He said that he'd like to write an article for a newsletter that he publishes (Tiros Space Information), and that he also writes for the US based SatMagazine.
    We did the interview, and he took a few photos. The results are here:

    Following the appearance in the newsletter, I was contacted by another journalist who was representing ScienceNetwork Western Australia (SNWA). SNWA is produced by Scitech, the state’s science and technology centre and supported by the WA Government’s Office of Science via the Department of the Premier and Cabinet. So it's kind of a big deal here in Western Australia.

    The article hit the website on 15th June 2015
     "DIY satellite launches from backyard shed to lower orbit"
    The media reach from this was unexpected! The article was aggregated by -

    And to top it off, the "Inside Cover" editorial in the only daily Perth based newspaper - The West Australian, picked up on it. Here's what page 2 of the paper looks like:
    As a bonus, the resident cartoonist - Dean Alston, drew a  cartoon with a humorous take on backyard launches!

    I had always wanted to try and inspire others with my project, so hopefully this media coverage will help with that goal. The humble backyard shed is where many great things can start!

    Sunday, 7 June 2015

    OzQube-1 CDH Design Complete

    I had joked on social media that the CDH had passed the KDR - The Kitchen Design Review. For those not in the know, this is a play on the name of the Critical Design Review (CDR) phase often used in aerospace. In my case, I was being very literal - I reviewed the design in the kitchen! I have settled on a final design for the first revision of the OzQube1 CDH ( Command and Data Handling) board. This is the brains of the satellite. It co-ordinates the recording of data from the various sensors including the camera and the transmission and reception of data from the radio. So what's inside?

    The OzQube-1 CDH

    The brains of OzQube-1 starts with an Atmel ATmega328P Microcontroller. This is the same microcontroller used in many Arduino boards, and is closest in design to the Arduino Pro Mini 3.3V . It is an 8-bit microcontroller that runs at a leisurely 8 MHz. It has a "massive" 2 Kilobytes of SRAM, and 32 Kilobytes of flash memory. So it's a long way from something like your mobile phone or your computer.

    In order to store the image data coming from the camera, a Micro-SD card is also incorporated onto the board. The Micro-SD can also be used to store telemetry data if required.

    The next piece is the 9-axis motion tracking IC from Invensense - The MPU-9250. It contains a 3-axis Gyroscope, a 3-axis Accelerometer and 3-axis Compass. This is used to determine the satellites orientation, and the measure the strength of the earth's magnetic field. 

    The next critical piece is the RTC (Real Time Clock). This, as the name suggests, is a clock. It can measure time more accurately that the microcontroller can, and uses a lot less power doing it. Unfortunately, because a satellite needs to have all power removed until it is deployed from the launch vehicle, it isn't possible to set the time in advance. It will only start counting once it has been deployed. It is possible to set the time remotely, but as there's no GPS onboard OzQube-1, the time will only be an approximation.
    The RTC provides another very useful function, which is a countdown timer. The RTC can alert the microcontroller once a specific period has passed. It is important to do this external to the microcontroller, as microcontroller can sometimes get a bit "distracted" performing other tasks, leading to incorrect time measurements.

    The remainder of the CDH is the local power supply arrangement. This includes a Watchdog Timer, which will reset the microcontroller if it hasn't toggled one of its inputs within a specified time. The electronics of the CDH are all 3.3V, but the EPS and Battery have a few different outputs. The EPS provides a regulated 3.3V for the CDH. This is the primary power source. If, for some reason, the 3.3V circuit fails, the CDH has its own circuit to take the battery voltage and regulate it down to the 3.3V required. This isn't as efficient as the EPS, but allows a bit of fault tolerance. Controlling all this is a small control circuit that will automatically switch and prioritise the power source.


    The main limit I found was the number of pins available on the microcontroller. The TQFP package of the ATmega328P has 32 pins. While I've managed to squeeze all the functionality into this design, I haven't stuck to the full PQ60 design specification. I'm not able to connect all the GPIO pins on the backplane to the microcontroller. 
    One possibility is to replace the ATmega328P with another in the Atmel family - the ATmega1284P. This is the same architecture, but has 44 pins, 4 times the flash memory capacity and 8 times the SRAM capacity. It can also be configured to use the Arduino development environment, so it can be programmed the same way. 
    Future satellites could use a different microcontroller architecture, but for OzQube-1 I wanted to stick to something that people are familiar with.

    Sunday, 22 February 2015

    Basic PocketQube Power Supply

    After posting a couple of pictures on Twitter of the small power supply I'd built for PocketQubes, I thought I'd give a bit more detail in a blog post.
    Even though I'm building a different EPS (electrical power system) for my PocketQube "OzQube-1", I wanted a small power supply that could power the satellite while I am testing it.
    I had a few requirements:

    1. It needs to be able to be powered from a plug pack (wall wart) or from an external battery pack. 
    2. It has to fit into the PocketQube PQ60 form factor
    3. It needs to output 3.3V and 5V
    4. It needs to have a similar current capacity to the real spacecraft EPS
    5. Cheap
    There is actually a very common thing that already fulfils most of these requirements - the humble breadboard power supply! The main issue is that they don't fit inside a PocketQube.
    Fortunately, I have a prototyping solution that's already in the PQ60 PocketQube form factor - ProtoQube.
    All that's needed now is a few components.
    If you look at a breadboard power supply, they often have a DC jack, and a USB input. The problem with USB is that there's often a 500mA current limit. This wasn't going to work for me, so I opted for a 2 pin screw terminal input. 
    Another issue with a breadboard power supply is the the voltage regulators. These are often SOT-223 surface mount parts. This is ok for a custom made power supply, but ProtoQube has a grid of holes, so a through hole regulator is needed. In order to keep the component count down, I went with fixed value voltage regulators. There are many on the market, so I went with some that were readily available - the ST Micro LD1117V50 and LD1117V33. These just need a single bypass capacitor on the input and output, and are capable of 800mA current.
    Finishing off the power supply are some pin headers for each rail, and a LED indicator to show when power is connected. I also added a diode on the input for reverse polarity protection. Here's the schematic to show how it's all connected:
    Assembling the power supply just requires some additional solid core wire, and the components arranged like you see in the pictures.

    All that's needed now is to solder on the Hirose FX8C backplane connector, and some female pin header sockets so I can connect the power supply output to the rest of the stack!