Close
0%
0%

Real-time OS automatic watering system

An expandable TI-RTOS automatic watering system, soon to be a smart IoT device.

Similar projects worth following
475 views
0 followers
The main motive for this project is to implementing RTOS on CC2652 by Texas Instruments. In my experience with making Arduino projects, I found that dealing with a fragile loop that controls all the operations in a project can be labor-intensive. As an Arduino application grows bigger, it'll become more and more nuisance to maintenance.

By implementing an RTOS, the application can escape the fragile loop, allowing the application to be more modular and thus making expanding the program less infuriating. RTOS can deal with real-time operations more effectively thanks to its priority mechanic.

The project at this point is quite frankly overkilled for such a simple application. However, I'll be expanding this project to perform wireless communications and become a smart IoT device.

Utilizing sensor controller:

One of the biggest advantages of using Texas Instruments MCU (I'm using CC2652 evaluation board) is its sensor controller. The sensor controller is a built-in CPU that can be used to read sensor data (ranging from digital and analog pins to communication interfaces like I2C and SPI). It can capture the data and store it in a structure that the main CPU can access easily. Most importantly, the sensor controller deals with event handlers, which have much lower priority than interrupts and ISR, allowing it to run in the background with little interference.

Implementing the sensor controller will free up the main CPU, thus allowing the main CPU to perform more tasks. As I want to keep its power consumption to a minimum, I program the logic such that it relies only on event listeners, which looks something like this (EH stands for event handler): 

As you can see, for the minimum implementation, the main CPU doesn't need to do a lot of work, most of the operations are handled in the sensor controller. In the future, I look forward to implementing the Zigbee stack into the main CPU to make this an operational Zigbee device. It can then be a part of a smart home IoT system. 

Water pump controller:

The logic is quite simple, there's 2 event handler, one to monitor the water level, one to control the water pump relay. As there's not a real way for the main CPU to directly interact and trigger an event, an internal comparator (known as COMPA by sensor controller) is used to generate the trigger signal. Pump activation EH will listen to the comparator output and control the pump relay. In the case where the water level EH detects a low signal (the sensor operates like a pull-up button), it will cancel the current pump activation EH trigger and make it listen to a low signal from the water level instead.

Sensor sampling:

The last event listener will handle the sensors. In practical application, an analog sensor needs to sample multiple times as each of the samples can vary greatly. Therefore, a sensor needs to sample multiple times so that the compute the average is more accurate. The sensor EH uses the timer to trigger itself and read the sensors at the correct timing. In this block diagram, each sampling value is separated by 1ms.

In addition to the sampling values, this EH also provides the value isReady. This lets the main CPU knows if the EH is in the process of reading and editing the sensor values or not. The main CPU can wait with while( isReady == 0 ) { } for the EH to finish. The output array structure of this EH and its timing is as follows:

The difference between single reading and multiple samples per reading is seen as follows: the values are more stable in comparison. 

Expanding the program (WIP)

Thanks to RTOS, a system can run multiple tasks. One important thing to notice: only 1 task can be operational at any given time. Most of the time a task is blocked by semaphore pend, event pend, message pend, or sleep. Once a task unblocked, it'll wait for its turn to run by the priority system, ensuring thread safety. One task can be pause mid-operation if another task with higher priority is unblocked, this is the key to a responsive and real-time application.

The main CPU will have global variables so that the tasks can share the resource. In this application, most of the resources are read-only and modified very rarely, so the tasks don't need to be strictly synchronized. The prototype will now look as follows:

Let's just appreciate how modular the entire system is. Each task can be individually modified without any worries of affecting another. The Zigbee client task can listen to multiple events from any task. To separate each event from another, we can use bit masking technique (where each bit corresponds to an event). If the system is connected to the cloud, the events can be notified to the users.

The next step is to implement the...

Read more »

  • Assembling the hardware

    Vinh Tran05/21/2021 at 06:44 0 comments

    Once I verified that my code works, I began assembling the project. The first step was to assemble the high-power component. Since the pump I'm using run on 110V AC, it's important that I isolate the high voltage terminal. I used an electrical enclosure to house all of the hazardous parts. This box contains both the pump relay and a 5V power supply (which is a USB phone charger that I modified to fit in the box). I had separated the 2 socket outlets so that 1 will have constant power while the other is controlled by the relay.

    Once everything is snuggly fit in this enclosure, it can now be handled relatively safely. The next parts to connects are the soil moisture sensor arrays and the water level switch, which are quite straightforward.

    Everything can now be assembled. The capacitive moisture sensor can be inserted in the side of the pot, while the watering head can be hot glued in place.

    Everything is set up and confirmed functional, time for me to start digging into applying the Zigbee stack onto the CC2652!

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates