ATTiny1616 Can Bus Controller PCB

Introduction

Over the last few months, we have been working on several prototypes, and some of our regular visitors may recognise some parts of this PCB. But let us begin by telling you what this is about.

As many of you may know, we have already designed several Can-Bus-related development boards, including one based on the ATTiny1616… So why the repeat then? Well, in some of my previous projects, I hinted at combining a buck converter, boost converter, lipo cell charger and Ideal Diode circuit into one PCB. I did at that time not tell you why.

To make a long story short, this project will eventually be used in my car, to provide more modern cabin lighting, which is quite a bit more than the standard on-or-off and on-when-open-the-door, off-when-close-the-door type of thing…

I own an old Honda City that I use mainly for a run-around to and from the farm, as well as seeing clients… Roads are bad, and this older car (actually quite old – 22 years) is the most cost-effective, in terms of being able to repair by myself, and not be worried about it if it gets a bit abused.

Unfortunately, the technology in the car is dated… a single yellowish cabin light right in the centre of the cabin – and not bright at all. Having to use the car at night, and then frequently scratching around in equipment bags when arriving at a client, becomes a pain with bad light… So I have decided to give it a bit of an upgrade and add CAN-bus-controlled NEO-Pixels to the cabin. For now, let’s say three sets, left, right and centre of the cabin. I also prefer a red light at night over white, especially if I have to drive again soon afterwards – a simple remnant from my days in the military, where it became quite clear how white light can temporarily damage your night vision.

NeoPixels can also be dimmed/brightened and seem relatively inexpensive.

Let us take a closer look at exactly what I want to do…

Powering the module

For the sake of clarity, this particular module will be installed front and centre in the cabin, just behind the rearview mirror. It will control two sets of 8 neopixels ( or up to 12 per module ) on two separate PCBs, which will cover the driver and front passenger area of the cabin.

The module will be powered by the vehicle’s 12v battery, as well as from a single 18650 Lipo cell. This means that we would need some clever tricks, in the form of a buck converter to step down the 12v to 5v, a way to monitor and recharge the lipo cell, a boost converter to boost the lipo cell voltage back up to 5v as well as a voltage “OR-ing circuit” to prevent reverse charging the lipo cell etc…

In its current state, the PCB is to be considered a test rig, since I have quite a few unknown variables that need to be thoroughly tested before actually installing this thing into a vehicle.

These are :
1) I would like to know if the ideal diode chip that I used functions well when used in a parallel setup, The reason for that is, that a single chip is capable of just about 1A of current… thus, in my reasoning, placing 3 in parallel would give me the 3A capability that I require – Let’s see if it does…
I could also not get hold of a suitable 3A capable ideal diode chip that was cost-effective, or did not have some strange MOQ or other logistics issues ( Yeah, seems like getting some stuff in SE Asia is difficult unless you are willing to pay unnecessary “special” charges and import duties etc … Element14 ( not sponsored) seems to have a limited selection of ideal diode solutions, but their pricing is good, and there are minimum hassles with shipping etc… I don’t bother with the other two big suppliers, D…. and M…. as they have too much red tape for a hobbyist to navigate to make it cost-effective to shop from them.))

2) Providing that the ideal diode solution does work as expected ( on the PCB) – having tested it on a breadboard seems to be working fine, there is the issue of monitoring the lipo cell, getting it charged, controlling the boost converter to provide power when needed etc…

All of this means that all the separate circuit modules on the PCB can be enabled or disabled by jumpers, and later, if all works as expected, maybe by another controller PCB… Who knows?

Getting back to power the PCB, I have used my standard buck converter circuit, based around the MP9943. This circuit seems to be very reliable, provides enough current, and is cost-effective.

I have also provided an auxiliary voltage output ( 5v) and some telemetry and control capability to the buck converter circuit, in the form of an enable-disable jumper, and the PG signal from the chip, to maybe be interfaced with a microcontroller later.

Charging the Lipo Cell

Once again, I made use of an existing circuit, with which I have had a lot of success in the past. This circuit, based on the MCP73832 from Microchip ( not sponsored) served me quite well in previous projects, and is once again, cost-effective and easy to implement. One negative is that they do seem to be a bit finicky, and not extremely robust – but when they work, they excel at it…

Once again, I decided to provide control logic to enable or disable this part of the circuit completely if needed.

Supply “OR-ing” circuit

This is the most experimental part of this entire circuit board, since, as mentioned above, the MAX40200 is rated at 1A maximum current. It is tiny and cheap, and also readily available… I am hoping that by using them in parallel I can achieve my goal of allowing the full 3A of current to flow from the buck converter, without releasing any “magic smoke” or other issues…

While, at the time of writing, I have not yet received the PCB, I am positive that all may just be fine, it remains to be seen how this will turn out during actual testing of the board.

Note that I have used a total of 6 of these, U8 to U11, with 3 per “voltage/current supply” channel. J3 and J4 are used to enable or disable the two supplies, with J3 being the buck converter input, in turn, powered from the vehicle 12v supply, and J4 begin the output from the boost converter, powered by the Lipo cell.

Boost converter circuit and MCU power

The boost converter is based on the MP3423, also from Microchip ( not sponsored). This circuit also performed very well in my initial test projects, with the only issue being it extremely tiny footprint, which really makes it quite difficult to use in a hobby environment, even with hot air and reflow equipment available… It is however also quite cheap, and readily available…

J5 provides enable-disable control to this part of the circuit.

With this relatively complicated power supply circuit, I thought it necessary to be able to completely isolate the ATTiny1616 and other integrated circuits from any power until I am completely sure everything works as planned…

J6A and J6B thus form a complete electrical isolation “breaker” that will prevent any voltage being provided to the microcontroller and other components on the PCB. I have doubled up on these jumpers, to allow for sufficient current flow, since I plan to use quite a few NeoPixels on this PCB… With up to 60mA of current required per pixel, that quickly adds up…

Voltage monitoring

Provision was made to monitor the output voltages of the Lipo Cell, and buck and boost converters by using the analog inputs on the ATTiny1616. These can be selected by setting the jumpers on J9, J10 and J11

Alternatively, the analog inputs can be used for other applications be leaving the jumpers off, in which case these GPIO’s will be available on H6 as PA4, PA5 and PA7

The ATTiny1616 microcontroller and UPDI programming port

The heart of this PCB is the ATTiny1616 microcontroller, (microchip, not sponsored)

I decided to use the chip once again due to its low cost, as well as the fact that I do not need a very powerful processor for this application. The only issue is that requires UPDI programming. In my case, I have had no issue with that yet, but other readers did mention that they had issues with them…

The UPDI header is at H1. This header can also be used to power the processor and other integrated circuits on the PCB independently from the Power supply, like in the case where J6A and J6B are left unconnected. This use case will provide me with more testing opportunities to test the board without possible variables from the power supply circuit(s).

Peripherals like I2C and the UART were broken out onto headers H3 for I2C, H4 for UART. These can also be used as GPIO pins ( remember to disable the I2C pullup in J1)

CAN-Bus Support

CAN-Bus support is provided by the MCP2515 (U2) and TJA1050 (U3) chips.

With access to the MCP2515 GPIO pins on H5. J2 is a 120ohm termination resistor, usually enabled at the start and end of the bus to prevent reflections.

CAN-0 is connected to the bus.
An additional 12v input/output header is provided at H7

NeoPixel Header H2

The NeoPixel strips are connected to H2. They are controlled from GPIO PA6 on the ATTiny1616. I have designed around a total of 24 of these at a maximum, with a total current requirement of 1.4A ( 24 x 60mA max per pixel / 1000 = 1.44 A) .

One important fact to know about NeoPixels is that the consume about 1mA per pixel even when in the OFF state. This is due to the internal control chip requiring power to operate. While 1mA bay be a very small amount of current, a lot of them does however quickly add up, and can thus potentially drain a battery completely over time…

To prevent this from happening, I have included a PMOS switch on the VCC pin at H2. This means that no power will be fed to the Neopixel strips unless you specifically pull GPIO PC1 low.

Manufacturing the PCB

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly and Testing

At the time of writing, the PCBs were still being shipped to me. Once I have received and assembled them, I shall publish a follow-up article specifically focused on that.

18650 Cell Boost Converter

As part of an ongoing project, this tiny boost converter was designed to be used to power some of my projects, as well as become a part of a much-needed add-on circuit to the single-cell 18650 charger PCB that I designed a while ago.

I received a lot of very useful comments from readers about the circuit below ( the single-cell 18560 Lipo charger). Most of these comments were related to adding a boost converter to the circuit, to add a little more versatility to the circuit.

I never just add something though, and as such, this boost converter prototype was designed to test out the components and design before incorporating it into the main design. That way, I can iron out any problems before adding it to a bigger circuit.

The boost converter is based on the MP3423GG-Z, from MPS. I have decided to stay very close to their recommended application notes, so the circuit is stock standard. Another way to ensure that performance is what I want it to be, and also, to be frank, because I don’t believe I need to make any changes to the manufacturer-recommended circuit.


Some other comments suggested the use of “ideal diodes” at the output , in order to be able to daisy-chain the chargers. That will be addressed in a later post this month, as I am also currently testing out one of the many “ideal diode” integrated circuit chips available – in this case the MAX40200.

Being a “prototype” I did not bother with adding proper connectors to this version, as it will only be used for a short while. Soldering the supply and output wires directly to the PCB will thus be sufficient for the time being.

Design and Manufacturing

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

This PCB really would benefit from having a stencil available when you assemble it by hand. The MP3423GG-Z is super tiny, so having a guide to apply just the right amount of solder paste to the pads will go a long long way to make sure that there is no reworking needed.


All of the other components are quite manageable, being only a couple of 0805 and 0603 resistors, and an inductor. I reflow soldered everything at the same time with a hotplate. It is worth noting that I did have to remove and replace the MP3423GG-Z once during the reflow process… tiny solder bridges formed between some pins, but carefully lifting it up with a pair of tweezers, and placing it onto the pads again got rid of those completely.

We may be tempted to “leave it off the board, wait for the solder to flow and then place the component onto the molten solder…” I am not too sure about the thermal stresses that that method may or may not induce in the component… so, I prefer having it heat up slowly with the rest of the components/ and then make a quick adjustment if needed… Comments on this anyone?

Testing and final thoughts

Testing the boost converter went without any problems. It delivers a stable 5.15v DC at the output, from an input voltage of 3.3v to 4.2v. I did not test it lower than that yet… Current output seems quite stable, and the voltage does not fluctuate under load ( I tested with 2 LED COB lights, each drawing 600mA, connected in series – thus 1.2A — That is definitely the maximum current that I intend to draw from this device, although it is rated at 3A

Ripple current seems to be within the 100mV stated in the datasheet.

In summary, I believe the device performs the intended duty that i set out to design. The assembly is a bit tricky due to the small size of the MP3423GG-Z, as well as my “not-so-good” eyesight. All that aside, I am ready to advance to the next phase of the overall project – revision 2 of the Single Cell 18650 Lipo Charger.

Lipo Cell Charger Rev 2.0 – A Combination of various circuits

A few months ago, I designed, what seemed at that time like an elegant solution to solve my 18650 Lipo cell charging issues. After publishing it online, I received quite a lot of extremely useful comments, most of which highlighted some of the shortcomings of that circuit.

Well, circuit is my attempt to address some of those, and turn the circuit into something that is actually useable…

What is on the PCB

To answer this, let us start at the core and work outwards. The 18650 Lipo Cell is charged using an MCP73832T chip. This chip will charge the cell up to a nominal voltage of 4.2v DC and accept an input of up to 6.0v DC…



This presented me with my first problem, as absent-minded me accidently fried quite a few of them when accidentally connecting 12v to a PCB…

My solution to this was to add a Buck converter, based on my previous 3A Buck converter circuit(s) using the MP9943GQ from MPS. The buck converter can accept between 7v to 12v DC and output a stable 5.3v DC, saving me from frying chips, and also making it useable with most of the power supplies lying around in my lab – and it can also be used in the car at a later stage — Future project —

While that keeps the MCP73832T happy, and the 18650 cell charged, the next problem that presented itself was the nominal voltage of the 18650 cell itself, which is usually between 3.2v and 4.2v. In order for this voltage to be universally useful to me I needed a boost converter to increase the output to 5.15v.

This boost converter was built around the MP3423GG, also from MPS. This tiny little 14 pin IC provides the 5.15v that I need with ease, at a rated current of up to 3A. Ideal for powering other peripherals, like LDO regulators to power an ESP32 etc…

Manufacturing the PCB

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

The assembly of this PCB was quite challenging, to put it lightly. 3 QFN chips, with different pad spacing, and small sizes really tested my limits. Needless to say, proper equipment is a must, and even then, a very steady hand and good magnification will go a very long way towards ensuring success… Another option would definitely be to have the PCB professionally assembled…


A stencil is definitely required for this one, is only for that 14-pin boost converter IC, to make sure that the amount of solder paste is just right – and even then, it is still a challenge!

Summary

This was a challenging build that tested my assembly skills quite a bit. The circuit functions like intended. Now it is time to add some more features, like an ideal diode chip at the output, to allow for daisy chaining the lipo cells if required, as well as maybe a microcontroller to control power to the buck converter when the battery is not being charged.

MAX40200 “Ideal Diode” Lipo Cell OR-ing prototype

This short post will cover a quick experiment using the MAX40200 “ideal diode” chip. I have plans to incorporate this device into my Lipo Cell charger to allow for combining cells to provide longer run-time for my projects, as well as using mains power where available.

For this reason, I replicated the manufacturer evaluation circuit for the MAX40200 chip to test it under my typical operating conditions.

I include a very detailed description from EZ.Analog.com below

There are three primary applications for ideal diodes. One is simple reverse voltage protection for a battery-operated device. This is simply a diode in series from the battery to the application circuit. The second is as a diode OR for high-reliability redundant power supplies. Last is the same diode OR circuit, but for a selection circuit between an on-board rechargeable battery and a wall charger—just like your cell phone and many portable equipment have. Ideal diodes (such as the MAX16915) are also used for overvoltage protection on power inputs.

A designer could move from a standard diode to a Schottky diode in all three of the applications mentioned. That will be a big help with forward voltage drop with the voltage going from 1.1V for a standard diode to around 0.45V at a 1A forward current. But, an ideal diode will take you down to 85mV at that current, and they don’t cost much. Plus, they are much, much smaller. An ideal diode IC reduces power consumption, cuts voltage loss (important when coming from a low-voltage battery), and will take less PC board area. Besides, they solve a big Schottky problem. Schottky diodes have a very high reverse leakage—around 1mA for the 1A device. This leakage is not good for primary batteries, in particular. An ideal diode typically has a reverse leakage of less than 1µA over temperature.

There are three ways to get ideal. You could make your own, use a driver IC for an external FET, or use a device with an integrated FET. Driving the FET is not as easy as you might think. It’s important that the drive circuit control the forward voltage drop across the MOSFET to ensure smooth current transfer from one path to the other without oscillation. If the power source fails or is shorted, a fast turn-off minimizes reverse current transients. Implemented correctly, an ideal diode can provide front-end protection against reverse battery conditions, overvoltage transients, and inrush current. Ideal diode controller ICs, using external FETs, are available with current ratings up to 5A and voltage rating to 80V.

A great example of a complete ideal diode device is Maxim’s MAX40200, which operates from a supply voltage of 1.5V to 5.5V, handles up to 1A, and comes in a tiny 0.73mm square 4-bump WLP or a SOT23-5 package. It is thermally self-protecting and works over -40° to 125°C. When disabled, the MAX40200 blocks voltages up to 6V in either direction.

The functional diagram in Figure 1 shows a unique symbol for the internal FET. The p-channel FET has added circuitry to sense the MOSFET drain-to-source voltage and, in addition to driving the gate, keep the body diode reverse biased.

It should be noted that, unlike normal diodes, this “ideal diode” is not suited for rectifying AC. In applications where the supply is an inductively coupled 60Hz AC, conventional diodes should be used for the rectification part of the circuitry. MAX40200 is designed to be used in applications to switch between different DC sources. The chip exhibits a regulated ~20mV voltage drop up to 100mA of forward current. Above that, the forward drop increases to roughly 90mV at the maximum rated forward current of 1A. This small voltage drop will increase efficiency and significantly increase battery operation times. The IC’s dynamic response is detailed in an application note, “Static and Dynamic Behavior of the MAX40200 in a Diode ORing Application.” And, an evaluation kit, MAX40200EVKIT, is available.

For example, a AAA battery has 1Ah capacity at ~3V for two cells. If a Schottky diode drops 0.36V at 1A and our MAX40200 drops only 0.09V, the 0.27V difference yields 0.27Wh saved. So your device will run an extra quarter hour at the 1A maximum load.

The IC has a thermal shutdown temperature of about +154°C with 12°C hysteresis. if currents exceed ~500mA, care must be taken in your design to not exceed this temperature. The thermal performance of the WLP package actually exceeds that of the SOT package.

What is on the PCB ?

The PCB is very loosely based on the  MAX40200EVKIT from MAXIM. I decided to design my own version versus buying the evaluation kit because it will , at least in my opinion, give me a better understanding of the component if I use it in a design that I have slightly modified…

What modifications did I make?
Not a lot, to be honest. I added two status LED’s and enable/disable jumpers.
Except for that, the circuit is stock standard from the example provided by MAXIM.

Why did I design this PCB?

The PCB was designed to thoroughly test the Diode “Or-ing” circuit, and to determine if it would function correctly when combined with my other circuits:
In this case, it will be incorporated into my LiPo Cell charger in the near future.

Testing the design

I am quite happy to say that, at least to me, everything seems to be working as expected. I measured a reverse voltage of below 120mV at the input of a disabled device, and the voltage drop of an enabled device is also below about 120mV.

The OR-ing function works quite well, as well as running the two MAX40200 chips in parallel, i.e. with both enabled. This resulted in a sort of “hot-standby” configuration, where the load is powered by the highest “supply” and then almost seamlessly switched over to the other when the first supply is removed…

This functionality does however require some more testing, as I am currently unsure if it is within the recommended operating parameters of the device, as well as if the perceived “hot-swapover” is as seamless as it seems… for example, while powering a 5v LED COB light from a bench power supply at 5.3 v, there is a noticeable diming of the LED when the bench supply is removed and the circuit runs only on the 18650 Lipo cell, which is boosted to 5.15v… with a subsequent brightening of the LED once the bench supply is reactivated…

This leads me to believe that the dimming may only be due to slight voltage differences, and could thus confirm my idea that a hot swap over is actually possible.

Manufacturing the PCB

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

Assembly is straight forward, with not difficult to-assemble components on the PCB. I did however order a stencil, as it is just part of my work-flow.

It is however completely possible to assemble this board completely by hand using a very fine tip soldering iron.

Conclusion

Using new devices – new to me, because I have not really encountered them before – can be quite exciting, especially if things turn out the way you expected, or even better than that. The challenge from this point onwards will be to properly incorporate the MAX40200 into the proposed circuit, as well as dynamically controlling each of the two MAX40200 chips to be enabled/disabled at the right time and at the right condition.

A Student designed ESP8266 Dev Board


This is a student-designed ESP8266 Dev board. This project came along after I challenged some final-year students at our local high school to try to design their own PCBs. They had recently assisted me in a collaboration with the Mushroom House Controller project, and while we were talking about electronics, the idea of a challenge came up, to stimulate some interaction.

One of them was extremely confident that he could do it, providing that I gave him a schematic. I complied, and he spent the next week hacking away on the EDA software. When i saw him again, he very proudly handed me a USB flash drive, containing the EDA design, but no schematic! Oh well, let us take a chance and see what happens… I mean, how bad could it be…

I took a good look at the design, making sure that it was at least electrically sound, with all the connections made to the right components, in the right way.

That part all passed, but, as we can clearly see, the layout could be very much improved. I decided to NOT change anything on the PCB, to keep the work original.

Manufacturing the PCB

The PCB, together with a stencil, arrived from PCBWay on about the 15th of this month.

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

The PCB was assembled with help of a stencil.

Technically, this PCB does not actually need it, as the components are large enough to manually place solder paste. This being a student project, I did however choose to get the stencil to try and assure the best possible chance of success..

Placing components only took a few minutes, after which the PCB was reflowed with hot air – no need for a hotplate here!

Through-hole components took only another few minutes to solder into place, and then testing could commence.

My thoughts – a very “gentle” critique

The board could be smaller, but due to the fact that this is a “very first PCB ever” and also a first SMD PCB at that, I can understand that it may still be quite difficult to understand how small the components really are, as well as lay them out properly.

Components are mostly all over the board, without a clear “group by function” kind of mindset. This once again comes back to experience.

GPIO pins are not notated. This will really make the board difficult to use.
The power supply input is in the center of the PCB. This is definitely not ideal.

In general, track sizes could have been bigger, especially on the Power and Ground lines. No ground plane was poured on either layer.

So does it work?
Yes, surprisingly it does. We shall see more of it in the near future, when I task the creator with using it to perform some task. That way, he can experience first hand the difficulties of the design, and also learn practically why certain things need to be improved.

A Simple IoT Plant Watering Solution

This is a Simple IoT Plant Watering Solution, done as another collaboration with the local High School in my Area. In this project, they took a group of purely academic students ( Language majors ) and told them that they had to design an electronics project that would have use in the real world…

This presented a very tough situation to the students since they had never even imagined that they could do something like this… (Think along the lines of a Senior Design project, like what you would give EE Students during their final year – with all the documentation, pamphlets, and explanations – i.e. lots and lots of paperwork) , and then also add on the requirement that they had to present a practical project as well! And they have only 45 days to do that as well!

I came into this picture late on a Thursday or Friday afternoon, with a group of students milling around outside the Electronics lab. They were unknown to me and seemed quite flustered… I invited them in, and eventually, they started opening up about their problem…

As it turned out, they were completely clueless, and did not know where to start with anything, not even what they wanted to do! Their initial idea went like “something that uses a camera to sort garbage by type and material” – that was never going to happen, not in 45 days, and not with the allocated budget of no more than $USD30.00 they were allowed. Lets not even go to the machine learning stuff, training of the models etc…

So, I took over, and decided that we shall do a simple IoT Plant Watering Solution. It is complex enough for Grade 11 students, and more importantly, I knew that I could teach them enough Arduino coding and basic electronics skills in the time allotted to get the project completed successfully.

What followed was a few very intensive sessions after school to get the paperwork sorted. For some reason, their teacher required ALL paperwork be completed upfront, with the entire design and code prepared before they touched the practical stuff – A funny way to design stuff if you ask me, but that is how we did it…

We settled on the ESP8266 12-E NodeMCU v3 development board, A resistive soil sensor, a DHT11 for temperature and humidity data, a small OLED I2C display and a small 5v USB-powered water pump. While they ordered the components, we started with basic coding classes, and this is where the story changes.

These kids blew me away with their level of interest, their attitude to learning, and how quickly they grasped the concepts. In no time at all, they were coding basic sketches, taking readings, learning how the different sensors worked, and pushing the envelope by adding lots more complementary components like MOSFETs and BJT transistors.


With this level of enthusiasm, I could not help but also become very excited, and thus decided to go a bit further than usual and help them design a neat PCB baseboard for the NodeMCU. That way, we could get rid of all those pesky wire connections, and maybe even produce something that looked good.


This is what we came up with, here shown just after SMD component placing. They ( the students ) did all of that by themselves as well, and it turned out to be a lot of fun for them, with some funny moments for me as well.

The Assembly ( First time ever )

The PCB, together with a stencil, arrived from PCBWay on about the 15th of this month.

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

This caused quite a lot of excitement from the students since they asked me to get to school immediately, and offered to stay after school to get the assembly done. So, I packed up all the components required, got in the car, and a few minutes later, we had an assembly line running 🙂


It took them only a few minutes to understand how to read the BOM file, use that information to find the right components and take turns to place a few components at a time onto the PCB. ( I did the solder paste and stencil thing on my own, as that could potentially turn out to be a very messy and wasteful operation if I let them do it )

During this assembly, they were quite amazed at what they were doing, but also quite confused as to how we would ” make the components stick to the PCB later”. They have seen soldering on YouTube, and could not understand how this “grey paste” could “turn hard and shiny” – with some even trying to rush their friends, as the paste would dry up and become sticky…

That signalled to me that we should get the hot air ready, and show them properly, as it would stop the speculation, and give them closure on their questions, because no matter how much I tried to explain that the solder paste would be melted later, they could not understand that concept.


Once I reflowed the first few components using hot air, they all once again took turns with a small group of components on the PCB ( We assembled 2 PCB’s to make sure everybody got a chance to try everything)


Through-hole soldering of the various header pins and other components was next. Once again, I showed them an example and then stepped back while they took over and completed the task. At this time it was about 17:30 already, so I sent them all home, with a promise to return the next day and complete the rest of the build.

Final Assembly and the Enclosure


We added some copper standoffs to the bottom of the enclosure, drilled some holes and mounted everything with screws and hot glue. The some final testing was performed, and the project was placed outside, next to a potted plant, and put on a sort of soak test, to verify operation for a few days.

A discussion of the circuit

In this circuit, I made use of a very cheap resistive soil moisture probe sensor. It consists of an etched PCB probe and a separate OPAMP on an additional PCB. This assembly then sends an analog voltage back to the Microprocessor for analysis. Very easy to use, and as mentioned, extremely cheap! But this is also a big problem. As seen in many other posts online, people don’t like these probes, as they don’t seem to last very long, and/or become unreliable over time.

I believe that this is due to the fact that they run them continuously, and that, causes the electrodes to erode away over time – because the thing about it, you are basically running an electrolysis cell – sending voltage/current through a probe, that is suspended in a conductive medium ( the water in the soil contains minerals etc – that is why it is conductive, and why we can get a reading from it )

How do I plan to avoid this problem then? The probe is powered through a small N-Channel MOSFET. This allows us to power the probe on when we want a reading, and then power it off again. It will definitely not completely stop the electrodes eroding away over time, but I am sure it will extend the usable lifetime of the probe by quite a bit. On the downside, you need another GPIO pin to control that MOSFET, but that in itself is also a great learning opportunity

Code

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32


#define DHTTYPE    DHT11     // DHT 11
#define WaterRelay 2
#define A0Enable 14
#define DHTEnable 13
#define DHTPIN 12
#define WATER_DELAY 10000
#define WATER_LOW 20.00
#define SOIL_DELAY 5000

uint32_t delayMS;
float temperature = 0.00;
float humidity = 0.00;
float soilValue = 0.00;
float soilAverage = 0.00;
unsigned long previousMillis = 0;
unsigned long previousWater = 0;
unsigned long previousSoil = 0;
bool MAY_WATER = 0;
bool RUN_WATER = 0;
bool DELAY_WATER = 0;
sensor_t sensor;
const String WaterOn = "Waterpump ON";
const String WaterOff = "Waterpump OFF";
String WaterMessage = "";

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
DHT_Unified dht(DHTPIN, DHTTYPE);



void setup() {
  
  pinMode(WaterRelay,OUTPUT);
  pinMode(A0Enable,OUTPUT);
  pinMode(DHTEnable,OUTPUT);
  digitalWrite(WaterRelay,HIGH);
  //Serial.begin(115200);
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.ssd1306_command(SSD1306_DISPLAYON);
  display.clearDisplay();
  display.display();
  delay(20);
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10,10);
  display.print("Booting...");
  display.display();
  delay(2000);
  
  dht.begin();
  
  show_DHT_Params();
  
}

void loop() {
  
  
  

  //Soil Monitor Loop
  unsigned long SoilMillis = millis();
  if ( SoilMillis - previousSoil >= SOIL_DELAY) {
    previousSoil = SoilMillis;
    take_soil_reading();
  }
  //End Soil Monitor Loop

  //Water Loop
  unsigned long WaterMillis = millis();
  if (WaterMillis - previousWater >= WATER_DELAY) {
    previousWater = WaterMillis;
    if ((digitalRead(WaterRelay) == LOW) && (RUN_WATER == 1) && ( DELAY_WATER == 0)) {
      digitalWrite(WaterRelay,HIGH);
      DELAY_WATER = 1;
    } else if (DELAY_WATER == 1) {
      DELAY_WATER = 0;
      if (RUN_WATER == 1) RUN_WATER = 0;
    }
  }
  // End Water Loop
  // Main One Second Delay Loop
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= delayMS) {
    previousMillis = currentMillis;
    get_DHT_Readings();
    show_Soil_Data();
    display.display();
  }
  // End Main 1 Second Loop
  if ((soilAverage < WATER_LOW) && (RUN_WATER == 0)) {
    RUN_WATER = 1;
    MAY_WATER = 1;
  } else if (soilAverage >= WATER_LOW) {
    RUN_WATER = 0;
    MAY_WATER = 0; 
  }

  if ((digitalRead(WaterRelay) == HIGH) && (RUN_WATER == 1) && DELAY_WATER == 0) {
      digitalWrite(WaterRelay,LOW);
      WaterMessage = WaterOn;
      take_soil_reading();
  }
  if ((DELAY_WATER == 1) && (MAY_WATER == 1)) {
      digitalWrite(WaterRelay,HIGH);
      WaterMessage = WaterOff;
  }
  
}

void take_soil_reading() {
  digitalWrite(A0Enable,HIGH);
  delay(50);
  
  float tempSoil = 0.00;
  for (int i = 0; i <10 ; i++) {
    soilValue = (1024.00 - analogRead(A0));
    tempSoil = tempSoil + soilValue;
    delay(2);
  }
  soilAverage = map(tempSoil/10,0.00,1023.00,0.00,100.00);
  delay(30);
  digitalWrite(A0Enable,LOW);
}

void show_DHT_Params() {
  digitalWrite(DHTEnable,HIGH);
  
  dht.temperature().getSensor(&sensor);
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10,1);
  display.print("Temperature Sensor");
  display.setCursor(10,10);
  display.print(F("Type: "));
  display.print(sensor.version);
  display.setCursor(10,20);
  display.print(F("Min: "));
  display.print(sensor.min_value);
  display.print(F(" Deg C"));
  display.setCursor(10,30);
  display.print(F("Max: "));
  display.print(sensor.max_value);
  display.print(F(" Deg C"));
  display.setCursor(10,40);
  display.print(F("Resolution: +/- "));
  display.setCursor(10,50);
  display.print(sensor.resolution);
  display.print(F(" Deg C"));
  display.display();
  delay(4000);
  dht.humidity().getSensor(&sensor);
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10,1);
  display.print("Humidity Sensor");
  display.setCursor(10,10);
  display.print(F("Type: "));
  display.print(sensor.version);
  display.setCursor(10,20);
  display.print(F("Min: "));
  display.print(sensor.min_value);
  display.print(F(" % RH"));
  display.setCursor(10,30);
  display.print(F("Max: "));
  display.print(sensor.max_value);
  display.print(F(" % RH"));
  display.setCursor(10,40);
  display.print(F("Resolution: +/- "));
   display.setCursor(10,50);
  display.print(sensor.resolution);
  display.print(F(" % RH"));
  display.display();
  delay(4000);
  
  delayMS = sensor.min_delay / 1000;
}

void get_DHT_Readings() {
    
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    sensors_event_t event;
    dht.temperature().getEvent(&event);
    if (isnan(event.temperature)) {
      #ifdef DEBUG-SERIAL
      Serial.println(F("Error reading temperature!"));
      #endif
    }
    else {
      display.setCursor(10,1);
     
      display.setCursor(10,1);
      display.print(event.temperature);
      display.setCursor(80,1);
      display.println(F(" C"));
      temperature = event.temperature;
    }
    // Get humidity event and print its value.
    dht.humidity().getEvent(&event);
    if (isnan(event.relative_humidity)) {
     display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    sensors_event_t event;
    dht.temperature().getEvent(&event);
    if (isnan(event.temperature)) {
      #ifdef DEBUG-SERIAL
      Serial.println(F("Error reading temperature!"));
      #endif
    }
    else {
      
      display.setCursor(10,1);
      display.print(event.temperature);
      display.setCursor(80,1);
      display.println(F(" C"));
      temperature = event.temperature;
    }
    // Get humidity event and print its value.
    dht.humidity().getEvent(&event);
    if (isnan(event.relative_humidity)) {
      #ifdef DEBUG-SERIAL
      Serial.println(F("Error reading humidity!"));
      #endif
    }
    else {
      display.setCursor(10,20);
      display.print(event.relative_humidity);
      display.setCursor(80,20);
      display.println(F(" %"));
      humidity = event.relative_humidity;
    }
    }
    else {
      display.setCursor(10,20);
      display.print(event.relative_humidity);
      display.setCursor(80,20);
      display.println(F(" %RH"));
      humidity = event.relative_humidity;
    }
    
}

void show_Soil_Data() {
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10,39);
  display.print(soilAverage);
  display.setCursor(80,39);
  display.println(F(" %"));
  display.setTextSize(1);
  display.setCursor(10,56);
  display.println(WaterMessage);
}

Conclusion

This project was extremely interesting. It was something very basic, but it gave me a very unique opportunity to teach a group of kids something they never knew before. It also initiated a spark in many of them, who are now interested in getting involved in electronics as a hobby. The possibilities of this project, if it is improved a bit more, could also be great. For example, we did not even consider adding IoT connectivity to this yet, we all decided that it was not needed, and an unnecessary complication of an already complex issue ( to the students that is). I shall keep monitoring the operation of the device over the next few weeks, and hopefully get some answers myself as to how long that soil probe will last… As a control, we have another one that was left powered on in the same container. That one are not being used to take readings, but will definitely provide us with a good comparison against the probe that is only on then used…

XIAO RP2040 Mouse Ver 3.0

Over the last few months, We have been steadily improving the design of our XIAO RP2040-based mouse device. With this, ver 3.0 all the hardware bugs were finally eliminated, and we also placed the device into its first-ever enclosure.

Let us take a look at the design

The PCB and Schematic


The PCB is a very strange shape, with lots of cut-outs. This is to accommodate the big push buttons that will be mounted in the enclosure, as well as to fit nicely into the mounting area of the enclosure… This design took quite some time with a pair of callipers and CAD, but all went well, and the shape is perfectly accurate.


The schematic is also straight forward, with the only real changes begin to the rotary encoder. In ver 2.0, We connected the encoder to the MCP23008, but for some reason CircuitPython does not seem to like an encoder connected to an IO extender… That forced us to do some software hack to use the encoder… I have thus decided to change things around in ver 3.0 and move the encoder back to the native GPIO on the XIAO RP2040

It is also interesting to note that the circuit was initially designed for the XIAO ESP32S3, but due to issues with stock, as well as crazy prices on local parts, we made a quick turn-around and went back to the RP2040. The ESP32S3 was going to allow us to implement a wireless device, through using ESPNow protocol… That may still be done in future, but for now, I think we have done enough work on the mouse device for the time being…

Manufacturing the PCB and Assembly

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here


Assembly was quite easy, I chose to use a stencil, because the IO Expander chip has a very tiny footprint, as well as a leadless package… The stencil definitely helps prevent excessive solder paste, as well as saves a lot of time on reworking later…


In the picture above, we can clearly see why I had to design the PCB with such an irregular shape.

Firmware and Coding

We are still using CircuitPython for the firmware on this device. It is not perfect, but it works, well sort of anyway. What does that mean? Well… As far as the mouse functions are concerned, clicking, scrolling, moving the pointer – all of that is works perfectly, and thus allows me to use the device for basic operations every day. Drag and Drop, as well as selecting and or highlighting text DOES NOT work. This seem to be an issue with the HID code in Circuitpython, meaning it doesn’t seem to be implemented. It is also way beyond my abilities to implement it myself…

Below is the code.py file, with the boot.py below that


import time
import board
import busio
from rainbowio import colorwheel
import neopixel
import rotaryio
import microcontroller
from digitalio import Direction
from adafruit_mcp230xx.mcp23008 import MCP23008
import digitalio
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23008(i2c)


from analogio import AnalogIn
import usb_hid
from adafruit_hid.mouse import Mouse
joyX = board.A0
joyY = board.A1
JoyBtn = board.D2

LeftBtn = 0
CenterBtn = 1
RightBtn = 2
UpBtn = 3
DownBtn = 4
EncoderBtn = 5


mouse = Mouse(usb_hid.devices)
xAxis = AnalogIn(joyX)
yAxis = AnalogIn(joyY)

# NEOPIXEL
pixel_pin = board.NEOPIXEL
num_pixels = 1
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False)

leftbutton = mcp.get_pin(LeftBtn)
leftbutton.direction = digitalio.Direction.INPUT
leftbutton.pull = digitalio.Pull.UP

centerbutton = mcp.get_pin(CenterBtn)
centerbutton.direction = digitalio.Direction.INPUT
centerbutton.pull = digitalio.Pull.UP

maint_btn = digitalio.DigitalInOut(JoyBtn)
maint_btn.switch_to_input(pull=digitalio.Pull.UP)

rightbutton = mcp.get_pin(RightBtn)
rightbutton.direction = digitalio.Direction.INPUT
rightbutton.pull = digitalio.Pull.UP

enc_btn = mcp.get_pin(EncoderBtn)
enc_btn.direction = digitalio.Direction.INPUT
enc_btn.pull = digitalio.Pull.UP

scroll_up = mcp.get_pin(UpBtn)
scroll_up.direction = digitalio.Direction.INPUT
scroll_up.pull = digitalio.Pull.UP

scroll_down = mcp.get_pin(DownBtn)
scroll_down.direction = digitalio.Direction.INPUT
scroll_down.pull = digitalio.Pull.UP



mousewheel = rotaryio.IncrementalEncoder(board.D6, board.D7, 4)
last_position = mousewheel.position
print(mousewheel.position)

move_speed = 3
enc_down = 0

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
BLACK = (0, 0, 0)


if move_speed == 0:
    in_min, in_max, out_min, out_max = (0, 65000, -20, 20)
    filter_joystick_deadzone = (
        lambda x: int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
        if abs(x - 32768) > 500
        else 0
    )
if move_speed == 1:
    pixels.fill(GREEN)
    pixels.show()
    in_min, in_max, out_min, out_max = (0, 65000, -15, 15)
    filter_joystick_deadzone = (
        lambda x: int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
        if abs(x - 32768) > 500
        else 0
    )
if move_speed == 2:
    pixels.fill(BLUE)
    pixels.show()
    in_min, in_max, out_min, out_max = (0, 65000, -10, 10)


filter_joystick_deadzone = (
        lambda x: int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
        if abs(x - 32768) > 500
        else 0
    )
if move_speed == 3:
    pixels.fill(PURPLE)
    pixels.show()
    in_min, in_max, out_min, out_max = (0, 65000, -8, 8)
    filter_joystick_deadzone = (
        lambda x: int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
        if abs(x - 32768) > 500
        else 0
    )
if move_speed == 4:
    pixels.fill(CYAN)
    pixels.show()
    in_min, in_max, out_min, out_max = (0, 65000, -5, 5)
    filter_joystick_deadzone = (
        lambda x: int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
        if abs(x - 32768) > 500
        else 0
    )


pixels.fill(BLACK)
pixels.show()
while True:
    # Set mouse accelleration ( speed)
    #print(mousewheel.position)
    if move_speed == 0:
        pixels.fill(BLACK)
        pixels.show()
        in_min, in_max, out_min, out_max = (0, 65000, -20, 20)
        filter_joystick_deadzone = (
            lambda x: int(
                (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
            )
            if abs(x - 32768) > 500
            else 0
        )
    if move_speed == 1:
        pixels.fill(GREEN)
        pixels.show()
        in_min, in_max, out_min, out_max = (0, 65000, -15, 15)
        filter_joystick_deadzone = (
            lambda x: int(
                (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
            )
            if abs(x - 32768) > 500
            else 0
        )
    if move_speed == 2:
        pixels.fill(BLUE)
        pixels.show()
        in_min, in_max, out_min, out_max = (0, 65000, -10, 10)
        filter_joystick_deadzone = (
            lambda x: int(
                (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
            )
            if abs(x - 32768) > 500
            else 0
        )
    if move_speed == 3:
        pixels.fill(PURPLE)
        pixels.show()
        in_min, in_max, out_min, out_max = (0, 65000, -8, 8)
        filter_joystick_deadzone = (
            lambda x: int(
                (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
            )
            if abs(x - 32768) > 500
            else 0
        )
    if move_speed == 4:
        pixels.fill(CYAN)
        pixels.show()
        in_min, in_max, out_min, out_max = (0, 65000, -5, 5)
        filter_joystick_deadzone = (
            lambda x: int(
                (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
            )
            if abs(x - 32768) > 500
            else 0
        )

    current_position = mousewheel.position
    position_change = current_position - last_position

    x_offset = filter_joystick_deadzone(xAxis.value) * -1  # Invert axis
    y_offset = filter_joystick_deadzone(yAxis.value)
    mouse.move(x_offset, y_offset, 0)

    if enc_btn.value and enc_down == 1:
        move_speed = move_speed + 1
        if move_speed > 4:
            move_speed = 0

        # print (move_speed)
        enc_down = 0

    if not enc_btn.value:
        enc_down = 1

    if leftbutton.value:
        mouse.release(Mouse.LEFT_BUTTON)
        # pixels.fill(BLACK)
        # pixels.show()
    else:
        mouse.press(Mouse.LEFT_BUTTON)
        pixels.fill(GREEN)
        pixels.show()

    if centerbutton.value:
        mouse.release(Mouse.MIDDLE_BUTTON)
    else:
        mouse.press(Mouse.MIDDLE_BUTTON)
        pixels.fill(YELLOW)
        pixels.show()

    # Center button on joystick
    if maint_btn.value:
        mouse.release(Mouse.LEFT_BUTTON)
    else:
        mouse.press(Mouse.LEFT_BUTTON)
        pixels.fill(GREEN)
        pixels.show()

    if rightbutton.value:
        mouse.release(Mouse.RIGHT_BUTTON)
        # pixels.fill(BLACK)
        # pixels.show()
    else:
        mouse.press(Mouse.RIGHT_BUTTON)
        pixels.fill(PURPLE)
        pixels.show()

    if not scroll_up.value:
        mouse.move(wheel=1)
        time.sleep(0.25)
        pixels.fill(BLUE)
        pixels.show()

    if not scroll_down.value:
        mouse.move(wheel=-1)
        time.sleep(0.25)
        pixels.fill(CYAN)
        pixels.show()

    if not scroll_up.value and not scroll_down.value:
        for x in range(4):
            pixels.fill(RED)
            pixels.show()
            time.sleep(0.5)
            pixels.fill(BLACK)
            pixels.show()
            time.sleep(0.5)
        microcontroller.reset()



    if position_change > 0:
        mouse.move(wheel=position_change)
        #print(current_position)
        #pixels.fill(BLUE)
        #pixels.show()
    elif position_change < 0:
        mouse.move(wheel=position_change)
        #print(current_position)
        #pixels.fill(CYAN)
        #pixels.show()
    last_position = current_position
    pixels.fill(BLACK)
    pixels.show()

boot.py

import storage
import board, digitalio
import time
from rainbowio import colorwheel
import neopixel
import busio
from digitalio import Direction
from adafruit_mcp230xx.mcp23008 import MCP23008
import digitalio
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23008(i2c)



#button = digitalio.DigitalInOut(board.D8)
#button.pull = digitalio.Pull.UP

button = mcp.get_pin(6)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

Rstbutton = mcp.get_pin(7)
Rstbutton.direction = digitalio.Direction.INPUT
Rstbutton.pull = digitalio.Pull.UP

# NEOPIXEL
pixel_pin = board.NEOPIXEL
num_pixels = 1
pixels = neopixel.NeoPixel(pixel_pin,num_pixels,brightness=0.2,auto_write=False)

RED = (255, 0, 0)
YELLOW = (255,150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
BLACK = (0, 0, 0)

# Disable devices only if button is not pressed.
#usb_hid.enable((), boot_device=2)
if button.value:
   pixels.fill(GREEN)
   pixels.show()
   storage.disable_usb_drive()
   usb_cdc.disable()
else:
    pixels.fill(RED)
    pixels.show()
    usb_cdc.enable(console=True, data=False)
    storage.enable_usb_drive()


time.sleep(5)
# Write your code here :-)

Assembling the Mushroom House Controller – Part 2

A Collaboration with Maesai Prasisart School, Measai, Chiang Rai, Thailand


In part two of the project, we let the students assemble the Mushroom house controller that they helped to design. It is important to note that they have never done any of this before, and also that most of the components are SMD.

This made for some interesting moments…

The PCB Arrives

The PCB arrived from the factory, and after an initial inspection by myself, we took it to the school so that a specially selected group of students can try their hand at assembling it.


One of the first remarks by the students was that everything was so tiny… Having never seen SMD assembly, they wrongly assumed that they would be required to manually solder the components using traditional solder and a soldering iron… This feeling of “dismay” was greatly increased when we started laying out the small bags with components.

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

The Assembly



To make things easier for them, I had previously selected all components, and together with a label and component designators, placed each component into a separate anti-static plastic bag. This achieved two things – it shielded the students from having to handle reels of components, potentially resulting in a lot of wastage, and it make it almost impossible to place a wrong component in a wrong place, as each of the bags were clearly marked with the specific component designator of the component it contained.


Their feelings of “dismay” were quickly replaced with wonder as I used a stencil to apply solder paste to the PCB. There were also confusing present, as they could not understand how the “sticky” solder would melt and keep the component in place. They were also quite worried about placing the components onto the PCB – that was until they saw that there was a selection of fine tweezers set out to use for exactly this purpose…

They now became very excited and took turns to each place a few components onto the PCB. I took special care to keep the diodes, optic isolators and microcontroller well away from them, at least until I explained that these components were polarised, or had to be placed in a specific orientation onto the board.

After a bit of struggling with the diodes, as well as the microcontroller, all the SMD components were eventually correctly placed onto the PCB. I now took over and used a hotplate to reflow the PCB.


This process completely amazed them, or at least, most of them, as some took this opportunity to continue with the ever present interaction of students and mobile phones that are so common in SE Asia 🙂

The PCB was now reflowed, and after a short break to let things cool down, we continued with the soldering and assembly of the through-hole components.


The proceedings would not be complete without a group photo of the students and the PCB that they assembled.

Conclusion of part 2

With the PCB now assembled, I used my desktop CNC machine to cut acrylic plastic to form a protective shell. The PCB will soon be installed at the remote site shown in part 1, and while it will be inside a IP65 electrical enclosure, I still felt the need for a little bit of added protection.

The firmware development is complete, and we are currently busy bringing the students up to date with the exact operation thereof. Our goal is that they would at least try to create their own version of the firmware for use in the electronics lab, as well as a comparison between my version of the firmware and theirs.

From the smiles on their faces during the entire process, it was quite obvious that they really enjoyed this project.

Mushroom House Controller – Part 1

A Collaboration with Maesai Prasisart School, Maesai, Chiang Rai, Thailand


A short while ago, the local high school in my area and myself decided to collaborate on a real-world project regarding an IoT device. The device (prototype above) will be used as a controller in an Oyster Mushroom growing house, which in turn will be managed by the members of a local disabled persons association. This is very exciting for a few reasons…

I will get the opportunity to teach interested students how to solve real-world problems using electronics, as well we will do something for the community and thus contribute to making the lives of the local disabled people a bit easier.

In the long term, the data collected by the device can be used to teach other mushroom growers in the area about the optimum environment to help them ensure that they get the perfect harvest every time…

In this post, I will thus do things a little differently from my normal setup, and focus more on the collaboration, as well as teaching moments. I shall also include quite a lot of pictures. The usual schematics and PCB descriptions shall still be available, but only on the PCBWay Shared projects page ( link to be added in due course)

The initial idea is to produce two different PCB’s with basically the same function, for the time being designed by myself. One, used in this post, will be a 3.3v version, with battery backup, and the other will be a 5v version, with level converters ( I could not resist the potential teaching opportunity that these provided) and no battery backup. The 5v version, which I shall introduce in part 2 will be assembled by the students, while I shall assemble the 3.3v version.

Further to that, the goal is to break the PCB up into logical modules and teach the students about each module. Their task would be to then design a PCB of that module, and in the end, combine all the modules into a functional project.
As a further part to this, a special interest group shall then make use of the knowledge learnt during the development of the modules to design a third PCB including all of those modules, as well as any other that they find may be needed, assemble it and use it in the real world.

Gallery – At the remote site

Over here, Grade 12 students assist in the construction of a mushroom house.
The pictures do not need a lot of captions, as they are quite self-explanatory

The next day, in the classroom

We started with a prototype on a breadboard, with some basic firmware. This was followed by a simple PCB design (with frequent 3D views so that the students could see what was happening)


This was followed by a practical session where the students had the opportunity to try their hand at designing a part of the PCB. It is quite important that we understand that this is the very very first time in their lives that they were ever exposed to this. They were all extremely excited and some grasped the concepts quite fast, while others took a more cautious approach…

Manufacturing the PCB

Now it was up to me to finalise the initial design and get it manufactured.


I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Conclusion – Part 1

The assembly of the first board was done by myself, and firmware development was started. Stay tuned for Part 2 where the students will get the opportunity to assemble a SMD PCB for the very first time in their lives…

Single Cell Lipo Charger

This single cell lipo charger was created to solve a problem I encountered during a recent project. I constantly needed to recharge 18650 cells, and while I could also use my 4-cell charger, that didn’t always turn out to be the most practical. I also intend to use this small charger as a building block for a future complete power solution, including a boost converter, more protection features and proper cell status indication…

I am currently moving towards building more projects that will be used outside, “in the wild” and thus need a reliable way to power those. True to my way of doing things, I want to build my own stuff as far as possible. That way, I learn more about the technology, and I am sure that everything meets my exact specifications.

What is on the PCB?

The charger is based on the MCP73832T, by Microchip, which contains quite a lot of useful features, in a small package as well at a relatively small price tag, and with very few other required supporting components.

  • Linear Charge Management Controller:
  • Integrated Pass Transistor
  • Integrated Current Sense
  • Reverse Discharge Protection
  • High Accuracy Preset Voltage Regulation: + 0.75%
  • Four Voltage Regulation Options:
  • 4.20V, 4.35V, 4.40V, 4.50V
  • Programmable Charge Current: 15 mA to 500 mA
  • Selectable Preconditioning:
  • 10%, 20%, 40%, or Disable
  • Selectable End-of-Charge Control:
  • 5%, 7.5%, 10%, or 20%
  • Charge Status Output
  • Tri-State Output – MCP73831
  • Open-Drain Output – MCP73832
  • Automatic Power-Down
  • Thermal Regulation
  • Temperature Range: -40°C to +85°C
  • Packaging:
  • 8-Lead, 2 mm x 3 mm DFN
  • 5-Lead, SOT-23

A proper screw-type connection terminal on the output, as well as a DC Barrel Jack on the input, completes the PCB. On future revisions, I will seriously consider having a voltage-limiting circuit on the input side, since the MCP73832T is only capable of accepting an input voltage of up to 5.5v DC.

This is not a problem to me, as I will be using the current version for my own personal use. I do however believe it is essential to ensure that no over-voltage conditions can accidently occur BEFORE I will give this to someone else to use.

The schematic

Manufacturing the PCB

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ), or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to who will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly and Testing

Assembly of this PCB was quite easy, providing that you have a stencil, it will not take you more than a few minutes.


The PCB’s really came out very nicely 🙂


I have also made provision for using a through-hole 18650 battery holder, just in case you are like me, and have a few lying around in a drawer, or could just not be bothered with using the SMD version…


The completed PCB is relatively small and compact, taking into consideration the size of the 18650 cell of course… The screw terminal on the output really helps to keep everything secure when using the module to power a project, and the DC barrel jack provides a good connection to charge it all back up again…
Now, If I just remembered to add some form of voltage limiting on the input, as well as include a boost converter, It would be the perfect little “power bank” project… For now though, let’s leave those features to the future, as this is already extremely useful as is.