Micropython and new horizons.

I have almost no real programming experience. I am ‘okay’ with computers, but most of it was all high-level UI kind of stuff. When I decided to get into Arduino as a hobby, it was because I knew that there were open source options for all of the IoT stuff coming to market, but I had no idea how to engage or hack any of those products. It seemed to me that a Google Home couldn’t be that complicated – or that a smart light was essentially just a wifi enabled on/off switch, which should be similarly simple.

I wasn’t wrong, but I wasn’t exactly right. Figuring out something as easy as a wifi controlled relay leads you into this world of computer science, programming languages, hardware compatibility and github (which I knew of, but was fairly intimidated by). I don’t know if diving into this rabbit warren was a necessary step or something particular to my personality (I am often confused by things until I can begin to understand their context.), but dive in I have been.

Arduino is a language based on C and C++. The underlying structure of the language is widely used and the Arduino language was developed by a helpful and dedicated community of people. Because of its legacy as one of the first hobby accessible microcontrollers, there was a concentration of people developing the language. But there are two limitations that I have encountered.

  1.  Because Arduino is based on a more complicated low level language (C, C++), writing new libraries and such requires substantially more ability and know-how than the casual hobby-ist. Luckily, the number of people more talented than I writing these libraries and code provides a wealth of examples and templates.
  2. The arduino IDE where you write the code needs to compile everything and translate it before loading it on the board and running it. This means that your workflow goes like this – code > compile > upload > run > error/unitended things > back to code > compile > upload > run > error/unitended things > back to code > compile > upload > run > etc etc. This means that it is difficult to quickly test and problem solve issues in your code, it also means that you spend a significant amount of time waiting to compile and upload code only to discover you made a typo somewhere.

This is where Micropython comes in. I came across micropython while experimenting with the ESP32 from Espresif. What an amazing little chip! I learned that Micropython is an implementation of Python 3 that was designed for the specific hardware constraints of microcontrollers.

Python and in this micropython has this wonderful little thing called a REPL. It allows you to pass code to the chip in real time and test out a section.like this:

>>> print(‘I am writing this in the REPL’)
I am writing this is the REPL

Python really is an elegant language. Very intuitive. The visual syntax of it is very clear and easy to read. For someone without much experience programming, it has an easily graspable internal logic.

The problem is that although its quite beautiful, it is far less common than Arduino and the number of libraries is far smaller. Now, you can leverage the huge python community for help, but there is going to be some stuff that doesn’t line up in the transition between a Python 3 and Micropython. Add to this the large number of hardware specific (relative to the size of the language) that have been made for various hardware… pyboard, circuitpython, microbit etc.

So, in a sense I am extremely excited by this new direction while also cautious … I think this will make me better at coding, but it might slow down the riparia project a bit.

So far I’ve written a few rudimentary scripts – a water level sensor that triggers a pump to top off the tank, a rudimentary light timer and a very basic thermostat/incubator for a horticultural project. All are just practice and proof of concept kind of things, but its exciting.

As always, the next big step (aside from adding more complexity to the operations) will be linking them to the net and getting wifi control, IFTTT hooks and wifi data-logging.

I really want micropython to surge, but also wondering if it makes more sense to run Python on a Pi Zero or something else.

Project Seal Laker (Level Midnight)

This is the newest project in the building to do list. With two motor actuated valves controlling the sump filter intake and and outflow pipes connected to  dealBreaker would be game changing.

Not only could you map the open/close ratio to a pair of potentiometers for manual control on both valves, you could also have the valves automatically calibrating based on something like a water level sensor located in the pump compartment of the sump. Or, perhaps the rate of flow changes through out the day with times of higher flow and turbulence followed by lower flow at night when a quieter tank is more desirable. The valves could also simulate rising and falling water levels – which would be handy for occasionally flushing out low lying areas of the shore.

Make no mistake, the Threat Level is Midnight.

Enclosure? What closure?

This is a slightly altered version of the design for DEAL BREAKER’s project box. It makes me look like I am much more proficient at this kind of thing than I actually am, but hey… fake it till you make it.

The box was designed on this great online editor called boxes.py. It is written in Python and you can use a limited online editor (which I did) or download the software and run it on your computer in python. The version that runs on your computer allows for much more customization.

Once I had the basic dimensions and attributes of the box figured out the program output this image as an .ai .svg or .pdf file.

I then brought the file into Illustrator and starting adding shapes for the various fittings I wanted to mount directly on to the box. This included the cut-outs for the panel mounted sensor plugs (3/4″ TRS (tip, ring, sleeve – typically used with audio – like electric guitars), the LCD screen, holes to mount toggle switches, indicator LEDs, holes for the wires fed into the relays and for the various tank lights.

For a lot of these I used the data sheets to get the correct measurements, which is probably the most I have ever used a data sheet… but for some of them I guestimated and surprise, surprise – its bitten me in the ass a few times already. The indicator LED holes are way to big and I have to figure out how to mount them now…

I sent the finished design to a local Laser Cutting Studio and they got the finished product back to me in about 5 days for $70. The studio also does acrylic cutting, which is more expensive, but good to know.

 

Project DEAL BREAKER – so close.

I made some major strides with Project DEAL BREAKER today.

I was able to fine tune the various DS1820 temp probes as well as use the DS3231 RTC’s internal temperature probe (it has this so it can calibrate the time keeping crystal and be much more precise than RTC’s with an external crystal) as a means to check the electronics enclosure temperature.

But the big jump was getting the Flow Sensor working. I found a pretty simple and easy to use library for flow sensors that does a great job. I was having a ton of trouble with it and because the code would compile and upload fine, I thought I had the electrical hookups wrong. I was pulling my hair out, but this library helped me out!

In the blurry photo below (again, lost my cool phone and used a potato instead) you can see the LCD display panel that sits above the tank as the main monitor. It tracks:

  • Date & Time (This is the DS3231 RTC – the key being that even if there is a power outage, the watch battery in the RTC (real time clock) will maintain the count and keep good time, so if the power turns back on, any scheduling based on the RTC’s time will be intact and up to date. )
  • Air Temperature and relative humidity (DHT22)
  • H2o temp using a ds1820 (display tank)
  • Sump temp using a ds1820 (10 gallon sump filter – where the heaters are)
  • Litres per minute (hoping to change this to hour… waiting on the geniuses on the Arduino forum for some help as I haven’t been able to figure out the conversion yet)
  • And lastly, the temperature of the electronics enclosure.

Very happy that the flow rate sensor is working. Its pretty interesting too. I am moving about 23 Litres a minute through the filter, which is about 1300 litres per hour. There is roughly 130 Litres in the aquatic portion of the tank, so I’m cycling the tank through the filter about 10 times per hour, which is great. It might be a little too much actually, but since its not crazy turbulent, I am considering keeping it at this high rate to see what effect it has on my water parameters… specifically, my ammonia is around .25ppm and I’d like to bring it down more – and my Nitrates are a little high – around 20ppm… I’d like to get it down to around 10. I also added a good chunk of filter floss to the sump the other day, so hopefully we’ll see the levels change some in the coming week or so.

I should note that the Serial Monitor that is available through the Arduino IDE offers more information, including what relays are on/off. This data will likely be included in the wifi expansion and sent to a database so that I can see over time how things like pump, air pump, lights etc impact the tank.

Next Steps:

  • Wire up all of the toggle switches and indicator LEDs
  • Wire up the relays and attach the Mains Voltage.
  • Clean up the wires and replace wires with colour coded custom fits wires.
  • Start operation REAL FAKER and implement Wifi connectivity.

Goddamn shit. Tank Update:

  1. Project DEAL BREAKER is going smoothly. It was a little harder than I thought it would be to implement, but that’s because I have switched some of the hardware around and some of the libraries didn’t talk well with one another. It is a reminder that I still have a lot to learn.
    At this point, I have almost everything working in concept. The relays are all working and (in theory can be) triggered by toggles as well as the DS3231 RTC at specific times. I have temps from three different temperature probes, the DHT22 temp/humidity sensor working well and I think I’m very close to have the Flow Rate sensor working. The code that I have for the Flow sensor compiles fine, but gives a funky number. I think its electrical noise, I need to add a resistor into the circuit, but I haven’t had time to do detailed electrical work recently… mostly just been rewatching the Sopranos and mulling over the code. When DEAL BREAKER is fully implemented, I will post the code and a more complete list of components to a post.
  2. After the main DEAL BREAKER stuff is done, the next step will be interfacing it with a ESP01 Wifi Module and start logging inputs on a MySQL database here – ie: PROJECT REAL FAKER.
  3. The above video is the first thing I ever made with an Arduino Uno and my introduction to this stuff. I had a rough idea of what Arduino was – a simple tiny computer that could prompt an output based on an input. If this, do this. So obviously its more complicated than that (or at least, it often is), but I ordered a kit off Amazon for $50 or so and its expanded exponentially since. Two years later and I basically need a barn where I can have an electronics lab, a grow/tank room and a painting/fabrication studio…
  4. Goddamn. I lost my phone. I went to a suburban fish store last week and bought some fish, a couple plants and another thing or two. I was writing an in-depth post for this blog while on the long bus ride back into Toronto proper, when I nearly missed my stop. I grabbed my fish friends and inadvertently left my phone on the seat beside me. In the large scheme of things in the universe – this is insignificant. In the tiny and self involved scheme of the universe- this is a giant pain in the ass. Not only do I not have a phone to appease my nervous fidgeting, I also can’t take photos of the tank as it rapidly progresses in this early phase. The dawning irony that my trip to fish store was about to double or triple in cost due to the replacement of my phone was also not welcome.
  5. I bought five more Panda Corydoras catfish for the tank. A giant and tragic flaw in my system: I recently found three Cory corpses in various stages of the sump weir. I thought that I had protected the opening enough, but it would appear that I had not. It was unfortunate, but I’ve temporarily over-covered the weir. The entire opening is stuff with polyfill. I think in the near future I may order a laser-cut acrylic insert that can be placed over the opening, allowing the full flow of water, but nothing big enough for a fish to get through.
  6. I also bought 8 Ember Tetras (Hyphessobrycon amandae) on the same trip. They seem to be doing well. They are colouring up and I’m looking forward to setting up a brine shrimp hatchery for them. Occasionally they will school together and its very cool – but I think there’s not quite enough of them to display shoaling behaviour all the time.
  7. I think once the tank chills out for a bit and I can get the water parameters under more control (more on that in another post), I would like to get a predatory fish – probably a pair of Dwarf Pike Cichlids so start regulating the Guppy population, and ideally, keep it at an absolute minimum. The guppies are already too numerous and I have a funny feeling that their random swimming behaviour disrupts the Ember Tetras shoaling. I think also just have a calmer tank with more substantial fish personalities would feel more resolved – hopefully, keep the water cleaner too.
  8. I also got a few more plants – a couple bunch of Sagittaria subulata and some Java Fern. Underwater garden is looking good, but they need some time to grow in. My Cryptocoryne Usteriana (I think) is doing pretty well. From what I have read, upon replanting they typically lose a lot of their leaves and send up new shoots and leaves once re-established. 2 of the 3 plants are sending up prominent new leaves, which is great. I would like to start Co2 injection soon, but apparently… this “hobby” is becoming “an obsession” and I have to “manage” my “time” and “money” more “responsibly“.
  9. Experiment update:  A little while ago I mentioned that I was trying to grow some aquatic plants in my hydroton sump tank emersed from the water. I have some Alternanthera reineckii, a rosebud of the same crypts I mentioned above as well as a year old, stunted and struggling Anubias in the sump. The anubias was a last ditch effort to see if the plant was worth keeping at all whatsoever.
    I am happy to report that all three plants are showing emersed growth. The Reineckii is growing the slowest, but you can see it has corrected its direction a couple of times and has tiny new leaves. The crypt is sending up a new leaf just like its buds upstairs and the Anubias is growing brand new, electric green leaves.All in all, the idea of have a sump with a “laborartory” in it is paying off. Any new sump design in the future will emphasize a space to work with plants (not to mention, grow food plants) within the system.

Cheerio.

Commence Preliminary Exploration Campaign in Project MEAL MAKER & REAL FAKER

I’ve added a tab in the primary menu of this site called ‘Data Trove’ – it links to a php page outside of the wordpress template style and will hopefully display data from a variety of sensors in real time (or perhaps upon refresh).

Its an ongoing experiment and learning experience. Projects working with data and visualization will be henceforth known as REAL FAKER.

My goals for this are to have:

  • Continuous updates to the database once every 10 minutes
  • Long term historical data
  • The ability to export info to google sheets.
  • Simple visualizations – line graph etc
  • Display multiple databases

 

DEAL BREAKER Update 01

“In theory, there is no difference between theory and practice. But, in practice, there is.”

  • Boards mounted
  • Clock keeping accurate time (was previously a problem)
  • LCD set up (4 x 20)
  • Relays, sensors mounted and preliminary figuring out has begun.
    • I think I need to rewire the sensor mounts and use the black, red, yellow sensor cords. I butchered it last time and I can’t figure out if I’m grounding the wrong pin etc etc… its annoying and some of the soldering is brutal. Live and learn.
  • The RTC timer is working well, but the DS1302 rtc module does not have the capability or the libraries to use it as a timer. Will be purchasing the a DS3231 to replace it.
  • Lots more to do. I am somewhat rebuilding the code based on the previous versions. I’ve changed too much hardware and small adjustments are starting to infringe upon other parts of the system.
  • Have started playing with displaying data from a DHT22 online via a NodeMCU dev board, but I think that’s a long way away from getting the paludarium controller data online.

Operation DEAL BREAKER & MEAL MAKER

Tanks up and running. Guppies and 5 Panda Cories. I’m going to let the aquatic plants grow in for a bit before deciding what to do next in the water. The idea is to have a pretty dense curtain of stemmed plants that can block the PVC piping supporting the land area. Need to find more cheap stem plants.

The terrestrial plants are growing in nicely. They need to be trimmed soon.

Sump is working fine except for the noise. I have to figure that out. I know there’s a variable with the way that water moves around the system, but I can’t seem to find it. As of this writing, the tank gurgles and burps incessantly.

I need to find some more biological filtration media. Using Hydroton turned out to be a bad idea. Thankfully it was cheap and I like having it around, but it takes forever to sink (this means that as the water level in the sump fluctuates, the clay balls rise and fall, dislodging seedlings and stirring up any detritus on them. 98% of it is still floating after weeks. On the plus side, the tank is running, cycled and relatively clean right now with the current amount, so its kind of a silver lining to be able to add 130% more filter media. I would like to keep the hydroton as a top layer resting on whatever addition media I scavenge.

I also still need to figure out the lid situation. I want to buy a panel of Polycarbonite Plastic (stuff they use for greenhouse panels) but its an annoying thing to take on the bus, so I keep putting it off. And buying acrylic sheets is expensive. However, I think a lid will make a huge difference in the tank. The humidity shift would be really drastic and I’d be interested to see how the terrestrial plants react – especially some of the mosses that seem to just be sitting there.

I think the tank can sit for a bit and grow out – though I may get tempted to buy a dozen small tetras and a pair of Dwarf Pike Cichlids soon. I added 5 Panda Corydoras catfish to the tank last week and they are fucking awesome. I’m going to purchase 5 more for a nice school. They really do have an interesting behaviour to them – between their sociability and occasional high speed flourishes across the tank and up to the surface to gulp air, they are a great sitcom to watch in the tank.

Next big era of the project is the final phase of the Arduino implementation – code named ‘Deal Breaker’. The goal of operation Deal Breaker is to have the Mega, Relays, sensor boards, LCD, and lights and power supplies hooked up and securely installed in the enclosure.

Operation Meal Maker will be installing the wifi capabilities to that data gathered by the sensors is logged into a MySql database and available on this website.

Final Form… Kind of.

Here’s the current run down of what going on in the paludarium monitor.

Still working on placing the components. I am sick of making projects that have a poorly organized implementation. I am trying to figure out what makes the most sense in terms of minimizing wire mess.

I designed the enclosure on boxes.pi which is a super cool online Editor that lets you alter the dimensions and a few other simple variables of various box styles and then outputs to a PDF or .AI file. You can download the software for free and run it yourself, with more design freedom.

I had the designs cut at a local laser cutting shop on 3mm Baltic ply. They also cut acrylics, so my mind is already thinking of various new additions that could be cut in acrylic for the tank.

In the box:

  • 12v 10a power supply fed to a small board that supplies 12v for the 5630 LED lights. The same board uses a lm805 to drop the voltage to 5v for powering the Arduino and other devices.
  • Another circuit that delivers power from a 5v 30a power supply to the RGB LEDs and consolidates the data lines into a single wire for data out.
  • Arduino Mega 2560
  • RTC module to keep time
  • Small board to consolidate toggle switches, indicator LEDs and dimmer.
  • 8 channel relay board (not shown) to control electrical devices above the 5V supplied by the Arduino.
  • D1 mini. This has no purpose yet, but planning ahead and trying to make sure there is room for the future wifi expansion.
  • Fan to keep electronics from getting overheated.
  • 20*4 LCD screen to display temps and other data real time.