AI-Thinker AiPi Eyes S1 – Something interesting…


Ai-Thinker is definitely in my opinion one of the more interesting Chinese Electronics companies out there. Most of us will be very familiar with their NodeMCU ESP8266 as well as ESP32-S modules as well as Dev boards.

They also produce the very popular Ra01 and RA02 Lora modules…

What is less known about them is that they have a very active R&D department. Over the last few months, more than 8 months to be accurate, I believe that there seems to have been quite a dramatic change happening. Many RISC-V-based chips and modules started appearing on the AI-Thinker website, and I have also been fortunate to get my hands on a few of them.

The latest of these, the AI-M61-32S, is another one of these. The chip seems to be based on the BL-616 or BL-618 from Bouffalo Labs ( No spelling error there)

Information outside of China, and in English seems to be very sparse at the moment, but it does seem like there is a lot of potential here…

Let us take a closer look at the AiPi-Eyes-S1

The board is a very neat, but dense double-layer SMD assembly, with interfaces for a touch-screen, camera, speakers and microphones as well as USB ports and a firmware flashing port.

The kit also comes with an impressive number of peripherals, including a beautiful touchscreen, a small camera, speakers and microphones.

What are my thoughts?

As stated above, I find the kit very well designed, in the sense that it looks good.
The screen has very good resolution, and there seem to be enough peripherals to test out something… Why am I saying something?

1) According to the schematic, the screen and camera share GPIO pins, and can thus not function together – a definite minus point for me there.
2) There are NO free GPIO pins, and those that may be, very difficult to access – think small connectors etc
3) The demo program seems to cover some of the basic functionality of the chip, but not too much…

Let’s take a look at software support

At the time of writing, the kit has been sitting on my desk for just over 2 months. English documentation, beyond a quick guide to get the demo software running, is limited, if nonexistent.

The Touch Screen API is downloadable, but will take quite a while to decipher – It will be worthwhile though.

I have also received news from AI-Thinker that there is limited Arduino IDE support for the AI-M61-32S available. I don’t know to what extent, and will definitely explore that further in the future.

Further than that, there are links and examples for setting up some sort of API/SDK from Bouffalo Labs on the Ai-Thinker Website. Support documents seem once again to be sparse as far as English is concerned.

In conclusion

I see potential in the future for this new chip ( the AI-M61-32S ) or let’s just call it the BL-616 or BL-618 already. Ai-Thinker repackaged it into the popular ESP32-S form factor, so they seem to be hoping that it could be used as a drop-in-replacement for that.

Being RISC-V based, it is however still extremely new, and with all the various RISC-V standards currently out there, it will surely take some time to mature.

The development of an Arduino core to support it, is definitely a step into the right direction, if and only if, compatibility with existing libraries etc can be assured. That will definitely allow Makers and other hobbyists to start using the chip

As far as the AiPi-Eyes-S1 kit is concerned, well…
Full marks for aesthetics – it really does look good. As far as practical use or being fit for a particular purpose goes – not so much.

The board was clearly designed as a showcase of possible uses for the AI-M61-32S only. It was clearly not meant for use as a development board.

So, would I buy one right now? a definite NO on that. In the future, yes, maybe, providing that:

1) Documentation and information are updated and made easily available.
Slapping the words ” open source ” onto something does not mean that you can skimp on documentation. It is “open source” because the schematics are freely available, datasheets are available, and libraries and IDE support are available free of charge. “open source” does not mean to give someone a space shuttle, and not include the manuals, or at least a link to where to buy the manuals etc…

Xiao ESP32S3 Media Device Prototype

I use a lot of ESP32 modules in my projects, mainly because of the integrated WiFi and BT, but also due to their small size. There are however usually quite a few external components required, and sometimes, that can be a bit of a turn-off.

Having access to quite a few XIAO modules from SEEED studio, and with support for the ESP32S3 recently being added to ESPHome, my other goto for projects, I decided to create a simple prototype based on the SEEED XIAO ESP32S3. this module offers several attractive features, of which its small size is definitely a big plus. Add to that that it also has battery charging circuitry and quite a lot of flash memory, and it seemed like a winner…

Not that it doesn’t have issues of its own, the biggest being that you have to power it from 5v, and the absolutely super tiny flash and reset buttons.

Cost-wise, they are only slightly more expensive than the native ESP32 module, which, by the time you have added the external components, does not amount to any difference anymore.

I also wanted to test out some power-supply circuitry, so this seemed like a good project to combine those in as well.

What exactly is the project about?

It is a testbed for three(3) different things, with the first being the XIAO ESP32S3, with I2S sound as an ESPHome media device. That part, while working, is in my view not perfect yet, as ESPHome does not seem to be able to utilise the 8mb of PSRam available on the XIAO for use with the I2S Audio, yet anyway…

The second is having my, by now almost common, dc buck converter circuit directly on the PCB. I want to test that, in order to make sure that there are not too much noise being generated that could influence the ESP32S3, or, most importantly, the I2S module. A while ago, I built a custom I2S shield, and unfortunately, the power capabilities, or let’s be frank, the lack of sufficient power, turned that project into a big disappointment at any volume other than almost below 2%…

This will thus also serve as a way to revamp that idea, but with better power capabilities and more available current.

The third part is a direct result of the XIAO’s 5v power requirement. I reused my LM317G variable voltage circuit to provide power to the module. In my view, it would have been so much nicer if I could just supply 3v directly to the XIAO…

This also brings us to the battery charging capability. I would have loved to use that, but,
1) It seems that the battery voltage is internally stepped up to 5v and then back to 3.3v for the ESP32S3. comment anyone?
2) The available output (3.3v) does not provide a lot of current – surely not enough to drive an I2S module, does it? more comments, anyone?
3) I am unsure of any internal isolation in above mentioned charging circuit, thus, I was not willing to connect my own boost converter to the battery and use that to power external components…

So, until I get definite answers on these three, I won’t be bothering with powering the circuit from the battery… unless it is a big 12v one

So what is on the PCB?

3D Render of the PCB

As mentioned above, I had a few goals with this prototype. Let us take a quick look at the board and its components.

Starting bottom left, we have the DC input area. Here I chose to provide both a DC Barrel Jack, as well as a screw Terminal. Both can be used, but I believe the screw terminal will add a bit more flexibility in an actual installation inside an enclosure.

To the right of those, we have a 7-way header. This provides access to D7 to D10 on the XIAO, and, in my case, is labelled for use with the I2S module and a DHT11 sensor. ( you can of course use it for something else as well). The DHT11 header is on the far right in this picture.

At the centre-left, the components around U1 forms the DC-DC buck converter. This is set to supply 3.3v at a maximum current of 3A.

To the right of that, around TP1, is a jumper to that supplies the XIAO with 5v from U2 ( the LM317G ). It is important to note that you should leave this jumper disconnected at first power-up, and then adjust R9 while measuring between GND and TP1 to get a voltage of exactly 5v on TP1. This will prevent you from damaging the XIAO module. Once that is set, power down, and place a jumper on the center and right side pins. Make sure to NOT adjust R9 again with this jumper in place.

Center-right is the star of the board. The XIAO ESP32S3 Module ( marked U3)
Note the cutout for the USB-C connector at its top.

A reset button, marked RST, and two headers, one for I2C and another with additional GPIO pins completes the PCB.

Note that the XIAO ESP32S3 makes use of an external antenna on a short UFL connected cable. Make sure to attach this BEFORE you power up the board for the first time.

Manufacturing

Since I have made use of a SEEED Module, I sent this to SEEED Studio for manufacturing.

Seeed Studio’s Fusion service seamlessly marries convenience with full-feature capabilities in one simple platform. Whether you are prototyping or looking for a mass production partner or based on open source product customization requirements and other design manufacturing services, Seeed Studio Fusion service is catered to your needs starting with a simple online platform. https://www.seeedstudio.com/fusion.html

Assembly and Testing

I chose to assemble this project on my own. There was some issue with component availability, and since I have most in stock myself, decided to save time and do it myself.

Little did I know that I will be severely handicapped by a broken wrist a few weeks later. That little incident forced me to use my non-dominant hand, and resulted in an almost 3-hour-long assembly operation! All did however go well, and everything works as expected.

Testing went well, and after verifying all the voltages and connections, I uploaded some previously prepared ESPHome code to the board.

Due to the fact that this is still an early prototype, as well as some issues with ESPHome, I wont be releasing the firmware just yet. That will however happen in the near future.

Stereo I2S Shield – The next iteration…

Last month I started working on a Stereo I2S Audio shield for my ESP32-S development board. Those of you that saw that post will remember that I made some mistakes on the initial prototype, and had to repair it with a few “greenwire” connections.


The prototype shield also required the use of commercial I2S modules to be plugged into it, making for quite a cumbersome first iteration.

Stereo I2S shield stacked onto esp32-S dev board

I decided to do something about that, as the long-term use of this particular shield, as internet radio, with a further “dream” of using it as a remote media player for use from Home Assistant, is moving along well, with progress on the firmware being made slowly but surely.


I decided that, since the Audio Chips seem to be quite easily available, and are modestly priced, getting rid of the plug-in modules, and placing the chips directly on the shield seemed like the next logical step. I also broke out the gain pins of each chip and made provision for easily changing said gain with a jumper, individually for the left and right channels of the I2S Audio shield.

I decided to keep the logic level conversion circuit, as it worked well, as well as provided another layer of protection to the ESP32-S that drives the whole shield. ( These have recently been discontinued by AI-Thinker, but the Espressif version is still begin manufactured and supported).

The power supply section of the board remains the same as the previous version, with a dedicated 5v regulator feeding the Audio section, and a 3v regulator the logic level converters. (I may change this in future, as the ESP32-S board can easily supply the 3v required without overloading the regulator on the CPU board.

Current issues that are carried over from the initial prototype still remain though. The two I2S Audion chips seem to be QUITE power-hungry, pulling almost 2A of current from a 12v supply, with a modest volume of 10 out of a possible 100. This has been reduced down from an earlier 4A to 6A when using a different pair of 4ohm 3W speakers.

This is also one of the reasons for the separate voltage regulators on the shield.

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 that will do his/her best to resolve your issue as soon as possible.

Find out more here

Assembly

This project once again called for a stencil, as the QFN packages of the Audio chips are super tiny, with super tiny tracks and pads. A high-quality stencil definitely goes a long way in ensuring that just the right amount of solder paste is added to each pad. This also reduces the requirements for reworking a board with hot air to fix any solder bridges that might have formed.


The quality of a stencil says a lot about your PCB manufacturer, and in my case, I am extremely happy to say that PCBWay definitely delivers quality. Having used their services for close to 3 years now, I have not received a single faulty PCB or stencil at all. Yes, some PCB’s has had errors, but those were all MY errors. Design errors, not manufacturing errors.

Let us return to the assembly of this PCB, shall we…

As usual, the PCBs arrived very well packaged, and after a quick inspection and some random tests with a multimeter, It was time for solder paste and placing components, while listening to a piece of relaxing music… my way of relaxing…


After about 20 minutes of intense concentration, we have a PCB with all of the components correctly placed onto their respective pads, ready for reflow soldering.


I did things differently this time, by placing the QFN Audio chips in their positions at the same time as all the others. ( I usually drop them in place when the solder is in a liquid state, but with these, I was confident in the stencil, and as these chips were quite a bit more expensive than my usual projects [ over 3 USD each ], I wanted them to slowly get up to temperature, and spend as little time as possible at temperature as well. )


Reflowing was a success, and after inspection, no solder bridges were found. A detailed diagnostic with a multimeter with fine-tipped needle probes confirmed that there were no short circuits or bridges, and I could thus continue with the rest of the assembly – the various through-hole components, being mostly header pins, switches and a DC barrel jack socket.

The speaker wires were soldered directly to the PCB, due to the fact that being a prototype, I did not see the need to raise the cost even more by adding connectors onto a board that may not be used very long if it turns out that there is a problem somewhere.

Testing

The next stage was testing, using the software provided in the initial Stereo I2S Shield post. All went well, but, as mentioned above, I encountered the same high current draw issue, which resolved itself ( in a manner of speaking ) after I reduced the initial startup volume of the unit, and limited the maximum volume in the software.

I can now continue with firmware development, and sort out things like the rotary encoders for the volume and station selection, as well as look at adding an i2c display, and possibly a sd-card for stored music files.

Conclusion

The project is getting along quite well, and this iteration of the prototype did not have any design faults or errors. I am extremely impressed with the reliability of my PCB manufacturer, as their consistent quality products allow me to focus on design, and trust that whatever comes back from the factory will be exactly as I designed it.

While there are still quite a few issues to sort out on this project, I am confident that in the end, it will all turn out the way that I want it to.

ESP32-S in Arduino Form Factor

The ESP32-S is, at least in my opinion, one of the most versatile microcontrollers available to the Maker at this moment. It ticks almost all of my boxes for features required in a microcontroller, with a lot of gpio’s, WiFi, and Bluetooth, as well as a lot of storage space for code.

I do however have an issue with it, which I usually get around by designing a custom circuit board with a specific purpose. This is great for a project, but as most projects do not start on a custom-built circuit board, I am usually required to use a breadboard module. This is where my problems start. These modules are cumbersome to fit on a breadboard, to say the least, taking up a lot of space, and leaving very little space to connect to its pins with anything else.

Some of these modules do not even fit on the breadboard, making it necessary to hang one side off the breadboard or use two breadboards with a gap in the middle. I am quite sure many people can relate to this problem.

My second issue is that when you have done your breadboarding, and want to go to a permanent project, which does not always need a dedicated PCB, you are now required to either live with things on a breadboard, scary to say the least or have a “spider” with many modules and wires, in a box or partly on protoboard etc…

My Solution, the ESP32-S DEV Board, in Arduino Uno form factor

My solution

You can get your own copy here

While not the most elegant, personally I really like the size, and layout of the humble Arduino Uno, with its standardised pinouts, and a large number of addon shields available for the platform. This made me think, sure, there are already ESP32-based boards in this form factor available commercially, but why not make my own instead, as well as a few of my most used modules in a standardised shield form, to make my life just that little bit easier?

The picture above shows my attempt, with most of the GPIO broken out onto female header pins (except for the 6 gpio that are connected to the internal flash chip on the module).

The Blank PCB ( front )
PCB- Back

The PCB explained…

Power:
The board can be powered in two ways, either via the VIN pin ( at an optimal 7.0v DC – the LDO regulator can handle up to 15v, but I personally find that to stress it a bit hard ), which will use the onboard LDO voltage regulator to provide the needed 3.3v or from an external 3.3v PSU, which can provide a bit more current if needed…

There are also plenty of 3.3v and ground connections on the two 20-way headers to connect to other sensors.

Strapping Pins
All the required strapping pins are pulled up or pulled down, as per the datasheet, to 3.3v or ground respectively.

GPIO Pins
All GPIO pins are clearly labelled on the silkscreen to make it easier to use.
I did however not stick to the Arduino labelling convention, as I don’t always use the Arduino IDE, and the actual GPIO numbers are in my view, more useful then.

Flashing code to the board

It will be quite obvious that I did not include any USB-to-serial converter on the board, the reason for this being that, in my opinion,
1) it wastes space on the board
2) it is not actually necessary, as we can upload with an external uart adapter, or use OTA ( which I actually do most of the time )
3) In an actual project, that USB port is going to attract problems, especially if you give it to someone else to use…

A simple Arduino OTA sketch is available in the examples section of the Arduino IDE. It is easy to use and modify and does not need a lot to make it useable with your own sketch…

Antenna Cutout

As recommended by the manufacturer , I have chosen to place the chip inside a cutout on the top of the PCB, with no tracks nearby.

Figure 17: Keepout Zone for ESP32 Module’s Antenna on the Base Board

Although this is not the ideal “best position”, I found that this position worked well with previous designs, and have thus kept it at that.

General comments

As this board is mainly designed for prototype development, I did not bother with dedicated power connectors etc. I did however add proper wide tracks for all the power connections, an on-PCB-heatsink for the voltage regulator, as well as proper ground planes on both sides of the PCB, connected together with via-stitching where needed.

It is also very important to note that this is a 3.3v device. If you need to use sensors or peripherals that operate at other voltages, you will have to use external level converters.

Some assembly pictures

Schematic

Manufacturing

The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

You can get your own copy here

PCBWay

ATMega328 I2C Base Board

In this planned to be a short post, I will quickly take a look at a scaled-down version of the ESP-12E I2C Base Board. This one in particular has only two slots, without the dedicated ESP-Card slot.

The main reason for this PCB is that the original version was designed for easy prototyping and projects where enclosure space will not be an issue. This is especially true in the case of the actual project that this will be used in, as there are quite a lot of other, very bulky components, that all need to be fitted into a relatively small enclosure.

What is on the Board?


The board contains two 2×20 Pin Male Header slots, providing 12v, 3v, Ground and access to the I2C bus, as well as additional GPIO’s as provided by the module plugged into the slot. I have also decided to provide breakout access to these IO’s on the actual PCB.

This is a feature that was not yet implemented on the original prototype.
Additional Ground connections, as well as an I2C expansion port, used to interconnect to other Base Card modules were also added.

It is also important to note that the I2C bus is powered by 3v. Interface modules should take this into consideration ( mine does ).

Power is provided by an MP1584 Buck converter module.

What has Atmega328p to do with it?

I called it ATMega I2C Base Module due to the fact that I plan to design a custom ATmega328P prototype card specifically for this unit, with all possible IOs broken out to header pins. I found that this style of prototyping suits my development cycle quite well, as I really dislike using breadboards and wires.

As I try to reuse a certain PCB or design it to be as general purpose as possible, having access to ready-made modules that can be slotted into a base and programmed, really saves a lot of time.

Schematic

Manufacturing

Over the past eight years, PCBWay has continuously upgraded their MANUFACTURING plants and equipment to meet higher quality requirements, and now THEY also provide OEM services to build your products from ideas to mass production and access to the market.


The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following…
1) Click on this link
2) Create an account if you have not already got one of your own.
If you use the link above, you will also instantly receive a $5 USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.)
3) Once you have gone to their website, and created an account, or login with your existing account,

4) Click on PCB Instant Quote

5) If you do not have any very special requirements for your PCB, click on Quick-order PCB

6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.

7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).

8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.

Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.

Using a Rotary Encoder

As part of an ongoing project, I recently designed an expander card for my ESP-12E I2C Base. I am referring to this device( Atmega 328P Base PWM Controller Card). At the time of writing that article, I have not released any of the code for the project. This is a very short post, showing one possible way to implement a rotary encoder onto that particular device. (It can also be adapted for other devices, of course)

Arduino Style Code for using a rotary encoder

// Constants and Variables
const int encFWD = 8;
const int encREV = 7;
int aState;
int aLastState;
int encDir;
int encTurned = LOW;
int encLastState;
int encValue = 0;
int lastEncValue;
const int encInc = 10;

unsigned long lastEncDebounce = 0;
unsigned encDebounceDelay = 50;
const int encBtn = 9;
int encButtonState;
int lastEncBtnState = LOW;
int EncBtnValue = LOW;
int encBtnState;

void setup() {
  //Rotary Encoder
  pinMode(encFWD,INPUT_PULLUP);
  pinMode(encREV,INPUT_PULLUP);
  pinMode(encBtn,INPUT_PULLUP);
  // Init the pins in UNPUT Pullup Mode
  encTurned = LOW; // Flag for encoder

  encLastState = digitalRead(encFWD);
  //Serial
  Serial.begin(115200);
  //Status LED on D13
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

void loop() {
  lastEncValue = encValue;
 //Handle the Encoder Push Button
 encBtnState = digitalRead(encBtn);
 if (encBtnState != lastEncBtnState) {
    lastEncDebounce = millis();
 }
 if ((millis() - lastEncDebounce) > encDebounceDelay) {
    if (encBtnState != encButtonState) {
        encButtonState = encBtnState;
        if (lastEncBtnState == LOW) {
          EncBtnValue = !EncBtnValue; // Toggle the button Value
        }
    }
 }
 lastEncBtnState = encBtnState;
 // Handle the Rotary Encoder Dial
 aState = digitalRead(encFWD);
 if (aState != aLastState) {
    if (digitalRead(encREV) != aState) {
       if (encTurned == LOW) {
          encLastState = encTurned;
          encTurned = HIGH; // Set Flag
// Setting this flag will get rid of double value entries caused by contact
// bounce inside the encoder. I found it easier to implement this way
// as opposed to using software debouncing as with the button

       } else {
          encTurned = LOW; // Set Flag low
// This will ensure that the value is increased only once per "click"
       }
       if ((encValue < 300) && (encDir == 0)){
          if ((encLastState == LOW) && (encTurned == HIGH)){
            encValue = encValue + encInc;
            encDir = 1;
          }
       }
      
    } else {
      if (encTurned == LOW) {
        encLastState = encTurned;
        encTurned = HIGH;  
      } else {
        encTurned = LOW;
      }
      if ((encValue > 0) && (encDir == 0)){
          if ((encLastState == LOW) && (encTurned == HIGH)){
            encValue = encValue - encInc;
            encDir = 2;
          }
      }
    }
    encLastState = encTurned;
}
aLastState = aState;
encDir = 0;
// Print Some Status
if (encValue != lastEncValue) {
  Serial.print("Encoder Value Changed from ");
  Serial.print(lastEncValue);
  Serial.print(" to ");
  Serial.println(encValue);
}
digitalWrite(13,EncBtnValue);



}

I hope that this will be useful to somebody.

Fix Driver Issues with CH340G on Ubuntu 22.04 LTS ( and possibly other Linux Distro’s)

Having recently upgraded to Ubuntu 22.04 LTS ( After the local power-company managed to destroy my HP ML350-G6 server, with a UPS installed, with a power surge or something – still no answers — 🙁 ) on a new more modern Desktop computer, I found some intermittent issues with my ESP32 / ESP8266 and Arduino boards… The Serial port would not work at all ( on devices with CH340G chips )…

A quick online search found the following, link to the original article here,

Instructions for Ubuntu 22.04 LTS x86_64

Get the currently installed kernel version:

sudo apt-get update -y
sudo apt-get install neofetch -y
neofetch

I think it came with Kernel: 5.13.8-...

Install latest kernel (GUI solution):

sudo add-apt-repository ppa:cappelikan/ppa
sudo apt-get update -y
sudo apt-get install mainline -y
sudo apt autoremove -y

Run mainline and select the latest kernel (I tried, as of 16/05/2022, kernel version: 5.17.8-051708-generic)

After installation and reboot, run neofetch again and check if the latest linux kernel is loaded.

Install build tools (if not installed already):

sudo apt-get update -y
sudo apt-get install build-essential dwarves dkms make cmake -y
sudo apt autoremove -y

Install and fix CH34x drivers:

As per the guide here in sparkfun and https://github.com/juliagoda/CH341SER

git clone https://github.com/juliagoda/CH341SER
cd CH341SER
sudo make clean 

# The Makefile looks for vmlinux in a certain location (check that cat Makefile)
# we need to move that
# https://forum.proxmox.com/threads/kernel-module-not-found-when-compile-skipping-btf-generation.100974/
cp /sys/kernel/btf/vmlinux /usr/lib/modules/`uname -r`/build/

sudo make
sudo make load
lsmod | grep ch34*

# NOTE: if other/prev ch34x drivers are loaded (and you know they were not working), then you can unload them by:
sudo rmmod ch34x

# Plug and unplug your CH340 device again on the USB port
sudo dmesg

# plug un-plug your device and then verify:
ls /dev/tty*

# make it accessible
sudo usermod -a -G dialout $(whoami)
sudo chmod a+rw /dev/ttyUSB0 # if /dev/ttyUSB0 was assigned

# To unload:
sudo rmmod ch34x
# or 
sudo make unload

Disable some conflicting services.

It came out during my test, at least on my machine, a service for some external brail hardware was conflicting with the drivers. I saw that in sudo dmesg

... ch340 1-10:1.0: ch341-uart converter detected
... usb 1-10: ch341-uart converter now attached to ttyUSB0
.
.
.
... usb 1-10: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
... ch340-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0

It was apearing and dis-appearing. so I tried to hunt the service as such:

sudo systemctl list-units | grep brltty

I then disabled it:

sudo systemctl stop <brl service name or other service that is interfering and not needed>
sudo systemctl disable <brl service name or other service that is interfering and not needed>
sudo systemctl mask <brl service name or other service that is interfering and not needed>

for f in /usr/lib/udev/rules.d/*brltty*.rules; do
    sudo ln -s /dev/null "/etc/udev/rules.d/$(basename "$f")"
done
sudo udevadm control --reload-rules

LoRa Base Module with ATMEGA328P

I had a need to build a reliable LoRa device, in order to do some testing regarding range etc, for an upcoming project on a friend’s farm. The device needs to be ultra-cheap to manufacture, as well as little power as possible. To achieve this, I decided on using the RA-02 ( From AI Tinker, not sponsored) as well as an ATMEGA328P, which consumes very little current when put to sleep… ( The radio will be on standby the whole time though..)

Building this with a standard Arduino, or another ATMEGA powered development board can be quite messy ( as the picture below shows… )

RA-02 LoRa module with ATMEGA328P PCB – Quite messy !!

A standard Arduino will be even worse, as you need level conversion on the SPI pins, due to the fact that the RA-02 is a 3.3v device, with the GPIO, not being 5v tolerant (Yes, this is true, some other posts on Youtube and similar conveniently leave out this very important little caveat… )

This problem thus warranted a dedicated custom PCB, to be designed in stages, and thoroughly tested of course… And while doing that, I needed to design something that was modular and useable.

I came up with the following design, as a stage one prototype:

Stage 1 LoRa Base Module Prototype

The PCB is basically an Arduino Nano style PCB ( as far as IO is concerned ), with level conversion on the SPI lines ( SCK, MISO, MOSI, SS) as well as a Lora reset and IRQ pin ( which will be essential to wake up the processor later ).

As the prototype will mostly be used in the lab, with some outdoor tests later, provision was not made for battery charging circuitry. Two LDO regulators, 5v and 3.3v provide power to the ATMEGA328P and RA-02 from a DC input of 7.5 to 12v.

Level conversion is fixed at bi-directional 5v to 3v logic levels.

All unused GPIO’s are broken out onto headers.

Code can be uploaded to the MCU via ICSP or a USB-to-serial converter, as I did not add those on board, to save space and power later.

Control Pins are as follows:

RA-02 ModuleATMEGA328P
SCKD13
MISOD12
MOSID11
NSSD10
RESETD9
IQR(DIO0)D2 ( Interrupt 0 )
DIO1Not broken out on stage 1 Prototype
DIO2Not broken out on stage 1 Prototype
DIO3Not broken out on stage 1 Prototype
DIO4Not broken out on stage 1 Prototype
Pin connections between RA-02 and ATMEGA328P

The Schematic diagram are listed below

Schematic Diagram – Page 1
Schematic Diagram – Page 2
PCB – Top
PCB – Bottom

Software

The board is compatible with the LoRa library from Sandeep Mistry. Other libraries may work as well but were not tested yet.

A very basic test sketch follows below:
Note that this sketch does not have any power-saving. It is purely used to do a very basic radio test…
More detailed code will be released in later stages of the project ( more on that later )

#include <SPI.h>              // include libraries
#include <LoRa.h>

const int csPin = 10;          // LoRa radio chip select
const int resetPin = 9;       // LoRa radio reset
const int irqPin = 2;         // change for your board; must be a hardware interrupt pin

byte msgCount = 0;            // count of outgoing messages
int interval = 2000;          // interval between sends
long lastSendTime = 0;        // time of last packet send

void setup() {
  Serial.begin(9600);                   // initialize serial
  while (!Serial);

  Serial.println("LoRa Duplex - Set spreading factor");

  // override the default CS, reset, and IRQ pins (optional)
  LoRa.setPins(csPin, resetPin, irqPin); // set CS, reset, IRQ pin

  if (!LoRa.begin(433E6)) {             // initialize ratio at 433 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  LoRa.setSpreadingFactor(8);           // ranges from 6-12,default 7 see API docs
  Serial.println("LoRa init succeeded.");
}

void loop() {
  if (millis() - lastSendTime > interval) {
    String message = "LoRa TEST";   // send a message
    message += msgCount;
    sendMessage(message);
    Serial.println("Sending " + message);
    lastSendTime = millis();            // timestamp the message
    interval = random(2000) + 1000;    // 2-3 seconds
    msgCount++;
  }

  // parse for a packet, and call onReceive with the result:
  onReceive(LoRa.parsePacket());
}

void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}

void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  String incoming = "";

  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }

  Serial.println("Message: " + incoming);
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println("Snr: " + String(LoRa.packetSnr()));
  Serial.println();
}

Future Plans

Future plans for this project include the following:
– Integration of a LiPo battery charging module, with a boost converter, to enable the device to run on battery power.
– Integration with an ESP32 or similar, to build a simple GATEWAY device
– CAN-BUS controller integration, to allow for adding multiple sensors to one radio module
– IO card, with galvanically isolated inputs, as well as Relay outputs, for remote control and monitoring applications.



The PCB can be ordered, or the design files downloaded ( a free download ) from my Projects page at PCBWay soon…

This PCB was manufactured at PCBWAY. The Gerber files and BOM, as well as all the schematics, will soon be available as a shared project on their website. If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following…
1) Click on this link
2) Create an account if you have not already got one of your own.
If you use the link above, you will also instantly receive a $5USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.)
3) Once you have gone to their website, and created an account, or login with your existing account,

4) Click on PCB Instant Quote

5) If you do not have any very special requirements for your PCB, click on Quick-order PCB

6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.

7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).

8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.

Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.


Getting Started with the Raspberry Pi Pico — Part 2 of the Pico Series…

Welcome to Part two of my RPi Pico Series. You can buy yours from Cytron Technologies.
In this post, we will look at some more of the features of the board, as well as how to get started using this development board. I will focus on MicroPython in this post, and cover C/C++ in the next post.

But before we do that, lets run over some of the specifications of the board first…
The Python Stuff will be at the end of this post…

Board Specifications

Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces. Key features include:

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom
  • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz
  • 264KB of SRAM, and 2MB of on-board Flash memory
  • Castellated module allows soldering direct to carrier boards
  • USB 1.1 with device and host support
  • Low-power sleep and dormant modes
  • Drag-and-drop programming using mass storage over USB
  • 26 × multi-function GPIO pins
  • 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor
  • Accelerated floating-point libraries on-chip
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support

Utilities

What is on your Pico?

If you have forgotten what has been programmed into your Raspberry Pi Pico, and the program was built using our Pico C/C++ SDK, it will usually have a name and other useful information embedded into the binary. You can use the Picotool command line utility to find out these details. Full instructions on how to use Picotool to do this are available in the ‘getting started‘ documentation.

Pico Github Repo

Debugging using another Raspberry Pi Pico

It is possible to use one Raspberry Pi Pico to debug another Pico. This is possible via picoprobe, an application that allows a Pico to act as a USB → SWD and UART converter. This makes it easy to use a Pico on non-Raspberry Pi platforms such as Windows, Mac, and Linux computers where you don’t have GPIOs to connect directly to your Pico. Full instructions on how to use Picoprobe to do this are available in the ‘getting started‘ documentation.

PicoProbe Github Repo

Resetting Flash memory

Pico’s BOOTSEL mode lives in read-only memory inside the RP2040 chip, and can’t be overwritten accidentally. No matter what, if you hold down the BOOTSEL button when you plug in your Pico, it will appear as a drive onto which you can drag a new UF2 file. There is no way to brick the board through software. However, there are some circumstances where you might want to make sure your Flash memory is empty. You can do this by dragging and dropping a special UF2 binary onto your Pico when it is in mass storage mode.

The Code for the flash eraser is available below


/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Iden
/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// Obliterate the contents of flash. This is a silly thing to do if you are
// trying to run this program from flash, so you should really load and run
// directly from SRAM. You can enable RAM-only builds for all targets by doing:
//
// cmake -DPICO_NO_FLASH=1 ..
//
// in your build directory. We've also forced no-flash builds for this app in
// particular by adding:
//
// pico_set_binary_type(flash_nuke no_flash)
//
// To the CMakeLists.txt app for this file. Just to be sure, we can check the
// define:
#if !PICO_NO_FLASH
#error "This example must be built to run from SRAM!"
#endif

#include "pico/stdlib.h"
#include "hardware/flash.h"
#include "pico/bootrom.h"

int main() {
    flash_range_erase(0, PICO_FLASH_SIZE_BYTES);
    // Leave an eyecatcher pattern in the first page of flash so picotool can
    // more easily check the size:
    static const uint8_t eyecatcher[FLASH_PAGE_SIZE] = "NUKE";
    flash_range_program(0, eyecatcher, FLASH_PAGE_SIZE);

    // Flash LED for success
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    for (int i = 0; i < 3; ++i) {
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(100);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(100);
    }

    // Pop back up as an MSD drive
    reset_usb_boot(0, 0);
}tifier: BSD-3-Clause
 */

// Obliterate the contents of flash. This is a silly thing to do if you are
// trying to run this program from flash, so you should really load and run
// directly from SRAM. You can enable RAM-only builds for all targets by doing:
//
// cmake -DPICO_NO_FLASH=1 ..
//
// in your build directory. We've also forced no-flash builds for this app in
// particular by adding:
//
// pico_set_binary_type(flash_nuke no_flash)
//
// To the CMakeLists.txt app for this file. Just to be sure, we can check the
// define:
#if !PICO_NO_FLASH
#error "This example must be built to run from SRAM!"
#endif

#include "pico/stdlib.h"
#include "hardware/flash.h"
#include "pico/bootrom.h"

int main() {
    flash_range_erase(0, PICO_FLASH_SIZE_BYTES);
    // Leave an eyecatcher pattern in the first page of flash so picotool can
    // more easily check the size:
    static const uint8_t eyecatcher[FLASH_PAGE_SIZE] = "NUKE";
    flash_range_program(0, eyecatcher, FLASH_PAGE_SIZE);

    // Flash LED for success
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    for (int i = 0; i < 3; ++i) {
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(100);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(100);
    }

    // Pop back up as an MSD drive
    reset_usb_boot(0, 0);
}

Getting Started with MicroPython on the RPi Pico

Drag and drop MicroPython

You can program your Pico by connecting it to a computer via USB, then dragging and dropping a file onto it, so we’ve put together a downloadable UF2 file to let you install MicroPython more easily. Following the procedure below, you can install MicroPython onto the Pico in a few seconds…

1. Download and unzip the UF2 file below into a folder on your computer.

2. Hold down the Bootsel button on the Pico, and connect it to a USB cable that was already connected to your computer. ( This means, connect ons side of the usb cable to the computer, but dont connect the Pico yet. then hold down BOOTSEL, and connect the cable to the pico)

3. Now, release the BootSEL button

4. After a few Seconds, you will have a new USB storage device on your computer, called RPI-RP2

5. Drag the UF2 file into this USB Storage device. The Pico will reboot… You have now installed MicroPython on your RPi Pico

Accessing the MicroPython REPL

You can now access REPL from a serial terminal, or a MicroPython IDE , like Thonny…
I will show you how to do it from the Linux Terminal below.

The Pico will show up as a USB device called ttyACM0
you can find it by issuing the ls /dev/tty* command

Start minicom or your preferred serial terminal emulator

Press enter a few times, and you should get a REPL prompt

You can now test MicroPython on your Pico, by typing the following commands:

The complete MicroPython SDK for the RPi Pico is available for download at the link below…

In the next part of this series, we will look at using the Thonny IDE, as well as C/C++ to program the Pico

Welcome to our New Site

Welcome to our new website on www.makeriot2020.com. It has been a while, but I finally managed to get the domain and hosting issues sorted out. (It took some time as I am doing everything myself, as I believe that hiring a developer to do something as easy as a simple blog type site is a wasted opportunity to do something myself.)

I have become a bit rusted with these ICT skills, as I did not need to do these things for a few years now. This site will bring much-needed refreshing of my skills 🙂

As far as my older posts are concerned, the will stay available on the old google sites platform, as I don’t think it is good practice to move them here. The effort with recreating them, as well as updating all the links in previous posts to Facebook, is not quite worth the effort. That combined with some of the limitations on what is possible with google sites, made me believe that this is the best way to go, Old posts stay on old site, and new stuff goes here.

Feel free to tell me what you think about that in the comments below 🙂