Electronics – a little knowledge..

I see the Arudino boards in this project as a link from the “software universe” to the real world. We can write code to do whatever we want, and by virtue of these boards being self-contained, internet connected hardware devices, we can sync and integrate with the physical environment.

Electrical Engineering is a science with systems, practises and rules like any other. While I have a great deal of enthusiasm for it, my knowledge is a way behind. I understand digital systems, and enough analogue (“real”) electronics to hook up the basics. I own The Art of Electronics, but keep thinking to myself I need to attempt it again..

What’s the goal?

To have 12 bright LEDs (2 per side of a cube) powered by the Arudino MKR WiFi 1010 boards, controlled by the Arudino with varying brightness.

What’s the problem?

The microcontroller (MCU) of the board itself, the SAMD21 Cortex-M0+ – can’t provide anywhere near enough current from its I/O pins to drive that many LEDs: 7mA per pin x 8 digital outputs = 56 mA, vs the LEDs’ likely requirement of >350mA.

The solution in such cases is to use a transistor, like a MOSFET, for power gain: you “drive” it with a small amount of power, which is used to turn on the floodgates and allow a much larger amount of power to flow from a source. For this purpose I found and purchased some helpful MOSFET-based driver boards from Amazon.

There’s a complexity here – the MOSFET in question’s datasheet indicates that the voltage drop to be expected when using it as such (Vsd) is 1.8V. Given the Arduino board’s power supply when running on batteries is 3.3V, that leaves 1.5V for the LEDs.

LEDs typically are set such that their own voltage sits at between 1.8V and 3.3V, depending on their colour.  So for a flashy, ultra-bright situation, 1.5V won’t cut it.

Boost Mode to the rescue!

I chose the MKR WiFi 1010 boards because they have a great feature set: they have WiFi, and can run off LiPo batteries. There’s even a built-in power management IC, the BQ24195L, which automatically charges the battery when USB is connected.

In scouring the internet, finding and gate-crashing this thread on the Arduino forums, I found that that magic little IC can be programmed to operate in “Boost Mode” (aka USB OTG – On-The-Go mode), to generate 5V from the battery, even in the absence of a USB connection.

This discovery kicked off a journey of questions, problems and ideas – and it’s not over yet..

Not so easy..

It should have been straightforward. The BQ24195L’s datasheet, as linked above, says in order to enable Boost Mode we only need to set a couple of bits of an internal register of the chip via I2C, and flip the OTG pin to “high”.

Problems encountered along the way:

  • Understanding the I2C setup of the Arudino, and how to read/write registers. This was a case of trial-and-error, and involved creation of a set of debug tools whereby the Arduino board would connect to the WiFi and listen for instructions to read/write registers and set pins.
  • Working out how the OTG pin was hooked up and could be controlled from Arduino code. In the end, the Arudino core’s code showed that microcontroller pin PA18 could be accessed via PIN_USB_HOST_ENABLE – and that it was set to a default of HIGH (electronically inverted to LOW on the OTG pin) on startup.
  • Finding out that my board had a blown transistor. Writing the register and setting PIN_USB_HOST_ENABLE simply didn’t work. Thanks to some help (see some credits below!), I determined that the transistor (another MOSFET, Q3 on the board) was blown.
  • Looking for a workaround, and discovering both my boards have a manufacturing fault! By coincidence in the very area I’m working hard utilise, there’s a resistor (R25) entirely missing from my original board, and a replacement I ordered (which I’ve yet to power up).
  • That official Arudino core code.. is a bug, after all. I raised an issue, confused with the fact that the USB OTG spec suggests that the pin being set HIGH in code would be tied to ground if an OTG device was connected – that’s a short, which is bad. They confirmed, yup, it should only be an input.

Right now, I have my old board, with the blown FET removed, and missing resistor, actually working to produce 5V by chance (the OTG is “floating”, unconnected, and is seen as “high”).

I’m eagerly awaiting some official confirmation here about whether I have the right understanding:

It should be possible for me to set OTG high by setting PIN_USB_HOST_ENABLE low, but it failed because R26 was missing as a manufacturing fault on my boards [and my MOSFET Q3 was blown]?

I’ll create another post when things move forward here. I do wonder – and really, really hope – if a replacement board, with R26 present, might actually just work first time if PIN_USB_HOST_ENABLE and the control register are set correctly.

Thanks to…

…all of whom are awesome, kind people who have humoured my frustrating ravings thus far.

For reference, my ravings can be found here:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s