This is the fourth part of the meta-tutorial, where I talk about designing a cheap plant watering sensor. If you did not already read the first, second and third part please do it now. These parts contain a lot information which lead to this point of the tutorial.
The third part ended with step 18, planing the final firmware. There a decision was made about the language and style of the firmware. This article will focus on the code of the firmware itself.
Step 19: Write a Preliminary Firmware
In order to be able to do some final tests with the prototypes and be able to work on the final PCB, I need a firmware which is is very close to the final one. In the Atmel Studio, I start a new C++ project in a new folder.
The first thing I do is checking the chosen compiler options for the project. Everything looks reasonable, I just add the option --std=c++11 to the C++ compiler options to get the latest language features.
In a section below I will describe all modules I wrote and will point details about the functions. I obviously did not wrote the whole firmware sequentially in that order, instead I use a incremental approach to develop the software:
Create empty frameworks for all modules.
Create a header and implementation file for each module with the correct name.
Add the header comments, the namespace, #pragma once and the #include for the own header file.
At this point, each module should be ready, so I can easily add new functions to each module.
Start with the hardware module.
Write the initialisation for the hardware, like CPU speed, port directions and other important stuff.
Layout the interface for the hardware module and prepare empty implementation blocks to be filled with code.
At each place where code is missing, I write a comment // FIXME!! to be reminded that there is something missing.
Start the logic module.
Write the main entry point of the logic.
Call this entry point in the main() method of the firmware.
This is the third part of the meta-tutorial, where I talk about designing a cheap plant watering sensor. If you did not already read the first and second part, please do it now. These parts contain a lot information which lead to this point of the tutorial.
The second part ended with step 14, designing a first prototype PCB. So let us start with the next steps in this journey. This article will be the smooth transition from prototyping to the initial planing for a final design.
Step 15: Assemble and Check the Prototype
After receiving the prototype PCBs from OSH Park, I assemble one completely, including the cable and with one of the sensor plate prototypes as foot part.
Set the Fuses of the Microcontroller
The microcontroller ATtiny13A requires programming using SPI before it can be soldered to the board. There are special bits in the memory, called “fuses”, which control very basic settings of the chip. One of this fuse controls if the chip can be programmed and debugged via the debugWire protocol. This protocol just uses one single wire to program and debug the chip, bus has to be enabled first.
So I put the microcontroller into the programming adapter and connect everything via the Atmel ICE to the computer.
This is the second part of the meta-tutorial, where I talk about designing a cheap plant watering sensor. If you did not already read the first part, please do it now. It contains a lot information about constraints and decisions made which lead to this point.
The first part ended with step 11, building a working prototype with the selected key components. So let us start with the next steps in this journey.
Step 12: Analyse and Measure the Prototype
Never forget why you actually built a prototype. It is your tool to verify all assumptions you made in the design phase. To do this you need the right measuring instruments.
The Power Usage
I start measuring the current of the circuit. This will show if my assumptions about the battery life will be true. For this test I use a multimeter which has a good resolution measuring in the µA range. The multimeter I use is the Testo 760-3 which is not a very well known brand. Multimeters are usually really poor at measuring low currents on low voltages, so let us see if this will work.
I also use a Fluke 114, but this one has no current measurement. It is sometimes very handy to have two multimeters, one to measure the voltage and a second one to measure the current.
For the first test I program the MCU to do all the tests in a loop and connect the power directly to the second part of the circuit. Now the power is always on and I can measure the current used by the MCU while doing the measurement.
I just started an interesting new project: The Outmoded Sequencer Project. It is an minimalistic music machine. You can use a 8×8 “programming” matrix to create simple melodies which are looping endlessly. This melody can be changed while the device is playing it. Here a short demonstration:
The device is divided into several parts as shown here:
My goals for the project were:
Only outmoded, basic and cheap components.
As minimalistic as possible.
Maximize the fun with these limitations.
Read all details how you can build this sequencer on the project page: