Menu Close

Tag / tests

Plant Watering Sensor – Long Term Tests Take #2

I started a second take on the long term tests for the plant watering sensor. This tests are required to be sure, the measurements follow the expected cycles. After watering the sensor, the frequency should go down and while the soil is drying up, the frequency should go up the the initial value. Logging this […]

How to Design a Cheap Plant Watering Sensor (Part 4)

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 firstsecond 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:

  1. 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.
  2. 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.
  3. Start the logic module.
    • Write the main entry point of the logic.
    • Call this entry point in the main() method of the firmware.
    • Add the hardware initialisation to the logic.

At this point, I have the structure of the firmware prepared as planed. This structure will lead me through the development process. Continue Reading