Posts

Work with IoT devices on a standard computer using CircuitPython and the Adafruit MCP2221 breakout board

Image
The MCP2221 and FTD2302 are breakout boards that have a USB on one side and a series of structured and unstructured I/O pins on the other. The breakout boards have various GPIO, I2C other pins on them that you attach sensors, LEDs, or other components.  This lets you indirectly attach GPIO inputs and outputs to a regular computer.   Adafrut's CircuitPython Blinka library emulates the CircuitPython IOT  board interface that is the root of many of the Circuitpython distributions.  That interface sits between standard Python and computer-attached I/O devices.  It was originally designed to support the I/O pins of the Linux-based Raspberry Pi. In our case, it sits between standard Python and the I/O devices that exist on the other sides of the MCP2221 and FTD2302 breakout boards. The Stack Python Program Python 3.x Runtime CircuitPython Framework Circuit Python Blinka board adapter Breakout Board Definition Individual Drivers...

Surfacing things we know nothing about - What we know vs What we need to know

Image
Every nontrivial problem space consists of a multitude of issues, constraints, data points, and information-driven decisions. We try and understand or manage these conditions and variables based on our risk assessments which are biased by how well they are understood.  This effort is a continual iteration where we strive to collect and classify issues and variables as we run across them.  Some of these problems are very complex or outside our sphere of experience which forces us to pull in other disciplines or people with other experiences that may be able to identify additional requirements and constraints, unknowns, and uncertainties.  This article is in a draft and is subject to revision. I first heard the known-knowns   known-unknowns  and unknown-unknowns when a technocrat gave a speech over a decade ago.  I had no idea what they were talking about and later learned it was a decision-making and political modeling tool  https://en.wikipedia.org/wik...

Failure Analysis - Not thinking through connector locations

Image
Failure happens from time to time when building projects or creating things.  I'm lucky that most of my mistakes are fixable after the fact or that the cost is negligible. I have a 10 year old project I wanted to update.  It is a stack of three boards. The bottom board is an Arduino Ethernet The middle board is a spacer that raises the third board above the ethernet connector.  The middle board has been cut to avoid touching the Ethernet connector The top board a NeoPixel 8x5 LED array I wanted to add a Nokia 5110 LCD to the board to show status and configuration. This Arduino Ethernet board has some stuff going on.  The left side of the board looks like it is the side that we would expose through a bulkhead panel.  The right-hand side has a programmer connector. I made that a 90-degree right-angle connector so that I could plugin in a serial-to-USB adapter while a shield was stacked on top. The thing is to remember that the left-hand side is going to be mounted...

Adding an analog feedback tap to a 9g Micro Servo

Image
Internally the servo has a feedback loop that is driven off of a variable resistor.  The resistance value changes as the servo sweeps across its range of motion. This can act as a proxy for the servo's position.  You can buy servos with an extra wire that exposes the voltage across that variable resistor or you can make your own. Or, you can add your own sensing wire to the potentiometer. I have a bunch of the 9g micro servos for various projects.  The one below has an extra green wire coming out of it that is connected to an analog input on this ESP32 C3.  The ESP32 can see  the location of the servo while it is in motion. See the Video on YouTube Sample Program Output The checksweep.py  program in this GitHub repository FreemanSoft ESP Python   The sample MicroPython tester moves a servo from 0 degrees to 180 degrees in steps and then returns to 0 degrees.  It logs the analog value of the potentiometer at the end of every move. It is actually...

Use the Windows Mobile hotspot when your ESP32 C3 will not connect to any of your WIFI SSIDs

Image
I spent two weeks troubleshooting ESP32 C3 network connectivity issues.  They worked a couple of times and then just never connected after that. I changed the firmware, erased nv memory, and tried about 10 different solutions found in the forums.   In the end, the only reliable way to work with those particular ESPs was to create a mobile hotspot on my PC.  That works 100% of the time for me.  This is essentially Internet connection sharing  even if it is only for the local network. Getting the network working was important because the ES32 C3 doesn't support the file share mount for CircuitPython development.  I normally use rshell  for MicroPython work but rshell isn't CircuitPython compatible.  So I really wanted the Web Workflow which requires a working network connection. I farted around with a Seeed XIAO ESP32 C3 that wouldn't connect to the mobile hotspot.   It turns out that tiny device could only see my desktop if I attached the...

Shrinking an IP address to fit on the PCD8544 Nokia 5110 style LCD - MicroPython Example

Image
LCD status displays can really simplify troubleshooting IoT devices.  I need to know the IP address of the device. and MDNS doesn't always work for me.  I could log into my router to find the IPs of my devices but it is simpler to add a cheap display and log the IP address on the display.  I have a pile of cheap Nokia-style modules that are 84 pixels x 48 pixels. The Adafruit Python driver defaults to a 5x8 font which results in 6x10 dot character spacing. 5 lines at 10 pixels tall is more than 48 pixels but we don't need the last two padding rows because there is nothing below them. That turns out to be 14 characters on the 5110-style LCD.  IP addresses can be 15 characters if all 5 octets are 3 decimal digits. This means it is possible to lose the last character of an IP address as shown below. The separator characters don't need to be full fixed-width characters. We know they can be smaller than the digits used for the IP address octets.  The function down be...

Servo Pulse Width Modulation PWM and Timer Resolution for 1ms-2ms and 600us-2300us

Image
I moved an app from an ESP8266 to a Raspberry Pi Pico processor and none of my servos worked correctly. The servos moved but not the right amount.  Then I google-found someone that had given a completely different set of microsecond ranges.  It turns out they fixed the problem but did not understand why they had the problem.  The following type of explanation is not correct The setServoCycle(position) function can be used to set the position of the servo by passing the position parameter from 1000 to 9000. The values for duty_u16 are in microseconds instead of degrees. The servo values 1000-9000 represent 0-180 degrees Servo control is based on Pulse Width Modulation where the width of a pulse tells the servo its position.  The control pulse is between 1-2 msec in a 50hz cycle.  That 50hz translates into a 20msec period.  So basically the control pulse ranges from 5%-10% of the period.  That translates to 1000usec - 2000usec .  Servos are ...

Leveraging JQuery Sliders to drive MicroPython HTTP GET APIs

Image
IoT devices can be remote data viewers, remote data controllers, data capture devices, remote sensors, or remotely controllable endpoints for different actuators and controls. HTTP provides a great semi-standard way of calling into devices.  I end up putting an HTTP  API tier on all my network-connected IoT devices for either data or just for status.  HTTP provides a request-response protocol. It doesn't mean you  have  to present web pages. You  should  use an API testing tool and unit tests to exercise the device. Custom web pages present a lot better demo and are easier for us lazy types if the device can cough up some type of web page with working controls on it.  HTTP and have a lot of overhead. Know your use case. The end-to-end time for my browser request-response cycle is from 150ms to 300ms. That means the ESP8255 or RP2040 are only looking at 4 requests per second.  Dropping the response or using a lower overhead protocol would...