An I2C Matrix Keypad

The completed I2C Matrix Keypad

In a previous post this month I introduced my 4×4 matrix keypad. That keypad was designed to be directly interfaced to a microcontroller’s GPIO pins or alternatively to an IO expander chip like the PCF8574. That design, while working very well had the problem of requiring 8 GPIO pins to function correctly.

GPIO pins on a microcontroller can be considered very precious resources, and it should then be logical to assume that we should find a way to use these GPIO pins in a more conservative way, to allow us to interface more peripherals.

I solved this problem by integrating the keypad with an IO Expander on the same PCB. That will allow us to get away with using only 2 GPIO pins, and also open up the option of adding more keypads to the I2C bus, in the event that we need that many keys for a particular project.

The Schematic

I2C 4×4 Matrix Keypad Schematic

Looking closely at the schematic, we can see that it is exactly the same basic keypad circuit that I used in the initial design. The only difference is that in this design, I have integrated a PCF8574 directly onto the PCB.

Some additional features include selectable I2C Pullup resistors ( usually my microcontroller development boards already include those) that can be activated with a jumper when needed. There are also a set of address selection jumpers, making it possible to stack keypads together into a bigger keyboard if you require something like that. Note that, in this version of the hardware, I did not include headers for stacking.

The keypad can be powered by a DC power source of 3.3v to 5v.

The PCB

I2C Keypad PCB
3D Render of the I2C Keypad

The PCB is a double-layer board of 68.8mm x 50.8mm. Male header pins provide access to the connections as well as address and pullup resistor jumpers. In my build, I have mounted these male headers on the back of the PCB. That makes it possible to mount the Keypad in an enclosure without having the jumpers “stick out” and get in the way.

The top layer of the I2C Keypad PCB
Bottom Layer

Manufacturing

I choose PCBWay for my PCB manufacturing.
This month, PCBWay is also celebrating its 9th anniversary, and that means that there are quite a lot of very special offers available.

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

The assembly of this PCB was quite easy and quick. A stencil is not required. All SMD components are 0805 or bigger. It would thus be quite easy to solder them all by hand with a fine-tipped soldering iron.

I have however used soldering paste and hot air to reflow the components, as it is the fastest, in my opinion, and definitely looks neater than hand soldering.

After placing SMD components onto solder paste – ready for reflow soldering
After Reflow soldering with Hot Air

The board is now ready to solder the switches and header pins in place. As already mentioned above, I chose to assemble the headers on the back of the PCB to prevent them from interfering with any enclosure that I may later use with the keypad.

Final Assembly
Note that I assembled the headers onto the back of the PCB.

Testing and Coding

Testing the keypad consisted of a few steps, the first of which was ensuring that there were no short circuits, as well as that all the momentary switches worked.
This was done with a multimeter in continuity as well as diode mode, with probes alternatively on each column and row in turn, while pressing the buttons.

The next stage was testing the I2C IO Expander. This was done with a simple I2C Scanning sketch on an Arduino Uno. It did not do a lot, but, I could see that the PCF8574 is responding to its address and that the pullup resistors work when enabled. This test was repeated with my own ESP8266 and ESP32 boards, this time with pullup resistors disabled, as these boards already have them onboard.

Coding came next, and it was another case of perspectives. It seems like all commercial keypads do not have diodes. This affects the way that they work with a given library. It seems that software developers and hardware developers have different understandings of what a row and a column is.

This meant that, due to the fact that I have diodes on each switch, and the way that the library work – which pins are pulled high and which are set as inputs -, I had to swap around my rows and columns in the software to get everything to work. On a keypad with the diodes replaced with 0-ohm links, that was not needed.

A short test sketch follows below:

Note that with was run on an ESP8266-12E, therefore the Wire.begin() function was changed to Wire.begin(4,5); in order to use GPIO 4 and GPIO 5 for I2C

Another point to note is that the keypad Layout will seem strange. Remember that this is due to the diodes in series on each switch. That forces us to swap around the Rows and the Columns in the software, resulting in a mirrored and rotated left representation of the keypad. It looks funny, but believe me, it actually still works perfectly.

#include <Wire.h>
#include "Keypad.h"
#include <Keypad_I2C.h>

const byte n_rows = 4;
const byte n_cols = 4;

char keys[n_rows][n_cols] = {
    {'1', '4', '7', '*'},
    {'2', '5', '8', '0'},
    {'3', '6', '9', '#'},
    {'A', 'B', 'C', 'D'}};

byte rowPins[n_rows] = {4, 5, 6, 7};
byte colPins[n_cols] = {0, 1, 2, 3};

Keypad_I2C myKeypad = Keypad_I2C(makeKeymap(keys), rowPins, colPins, n_rows, n_cols, 0x20);

String swOnState(KeyState kpadState)
{
    switch (kpadState)
    {
    case IDLE:
        return "IDLE";
        break;
    case PRESSED:
        return "PRESSED";
        break;
    case HOLD:
        return "HOLD";
        break;
    case RELEASED:
        return "RELEASED";
        break;
    } // end switch-case
    return "";
} // end switch on state function

void setup()
{
    // This will be called by App.setup()
    Serial.begin(115200);
    while (!Serial)
    { /*wait*/
    }
    Serial.println("Press any key...");
    Wire.begin(4,5);
    myKeypad.begin(makeKeymap(keys));
}

char myKeyp = NO_KEY;
KeyState myKSp = IDLE;
auto myHold = false;

void loop()
{

    char myKey = myKeypad.getKey();
    KeyState myKS = myKeypad.getState();

    if (myKSp != myKS && myKS != IDLE)
    {
        Serial.print("myKS: ");
        Serial.println(swOnState(myKS));
        myKSp = myKS;
        if (myKey != NULL)
            myKeyp = myKey;
        String r;
        r = myKeyp;
        Serial.println("myKey: " + String(r));
        if (myKS == HOLD)
            myHold = true;
        if (myKS == RELEASED)
        {
            if (myHold)
                r = r + "+";
            Serial.println(r.c_str());
            myHold = false;
        }
        Serial.println(swOnState(myKS));
        myKey == NULL;
        myKS = IDLE;
    }
}

Conclusion

This project once again delivered what I set out to achieve. It has some quirks, but nothing serious. Everything works as expected, both in the Arduino IDE/platform IO realm, as well as in ESPHome. It is worth noting that in ESPHome, we do not need to swap the rows and columns to use the Keypad component. Do remember to leave the has_diodes flag to false though…

RP2040 Scoppy Oscilloscope Analog Front End Shield

This post will look at my prototype Analog front-end for the Scoppy RP2040 Oscilloscope. It is important to state right from the beginning that this circuit is one of the 5 recommended designs from the Scoppy Website. I have only moved it from the breadboard design as published, onto a PCB.

The entire circuit, with all of the original designer’s writeups, is available here

So, why use someone else’s circuit? Well, the reason for this is two-fold.
1) The circuit designer also designed the firmware, so it stands to reason that his circuit will be optimised for use with the firmware.
2) Using his circuit provides a solid reference, making it possible to test the firmware for correct operation, and later on, providing a base for my own design – if and when I do decide it is worthwhile to actually design my own.

As I already have a proper oscilloscope as well as a logic analyser, this entire exercise is purely academic, I find the Scoppy project interesting, and as such, I would like to see how it compares with my commercial products ( while also knowing that it won’t be a very fair comparison ).

With all the limitations, I am however still quite impressed at the level of use that you can get out of this very simple device. It is definitely quite useful for a beginner.

What is on the PCB, and what did I change?

The PCB is a dual-layer shield that is designed to be used with the MakerIOT2020 Raspberry Pi Pico Carrier board. The shield is directly powered by the carrier board.

The original Analog Front-End #3 circuit featured a single channel input, capable of accepting a -18.0v to 18.0v signal input.

My changes were limited to doubling up on that circuit, to provide two channels.

The Schematic


I have redrawn the original schematic, partly to make it easier to understand for myself, as well as to help me with the design of the PCB.

Lets take a look at the schematic ( by using text from the original designer)

The author makes no warranty, representation or guarantees regarding the suitability of this design for any particular purpose. Nor does the author assume any liability arising out its use and specifically disclaims any and all liability, including without limitation special, consequential or incidental damages.


All text below is quoted from here

This design builds on Design 2 and adds over and under voltage protection to the analog front end. After all, we won’t have a cheap oscilloscope if we keep frying our components!

I’m assuming here that the minimum and maximum voltages that will be applied to the input of the scope will be -18V and +18V respectively. It has been tested from -18.5V to 18.5V (two of my 9V batteries in series) but of course If you decide to use this design you are doing so at your own risk. I personally wouldn’t use Scoppy with an expensive phone/tablet just in case something unexpected goes wrong (better to use an old, obsolete phone that is no longer used for anything else) – especially when dealing with higher voltages – but of course you can do what you like.

Protecting the Op-Amp input(s)

First of all we need to protect the op-amp. In this design we’ll be using an LM324 op-amp, which is very similar to the LM358 but contains four individual op-amps rather than two. We’ll be using three of these op-amps. The reason for this will be explained later.

According to the datasheet for the LM324 the allowed input voltage range goes from -0.3V to 32V. Of course 32V is above the maximum expected voltage (18V) and so we don’t need to worry about over-voltage protection. However we do need to ensure that the voltage at the input pins don’t go below -0.3V. A schottky diode can be used to clamp the voltage to something above -0.3V (D1 in the schematic).

One thing that needs to be considered when selecting the diode is its reverse current. The 1N5817 has a very low forward voltage but high reverse current and this results in a voltage drop at the input of the op-amp (in the order of 100mV). Presumably this is because it draws current through the high value input resistor (Rg1). The 1N5711 has a much lower reverse current specification and I couldn’t discern any voltage drop when this was inserted into the circuit. However, its forward voltage (at the current expected in this part of the circuit) is very close to the minimum allowed voltage of -0.3V. To be safer I prefer to use something like a BAT46. It does result in a voltage drop of a few millivolts but the clamped voltage is more like -0.23V.

Protecting the Pico/RP2040

The Pico datasheet states that:

the ADC capable GPIO26-29 have an internal reverse diode to the VDDIO (3V3) rail and so the input voltage must not exceed VDDIO plus about 300mV

The obvious way to protect the ADC inputs (GPIO26-29) then is to simply insert a schottky diode between the ADC input and VDDIO. However, the RP2040 datasheet says that:

the voltage on the ADC analogue inputs must not exceed IOVDD ...<snip>... Voltages greater than IOVDD will result in leakage currents through the ESD protection diodes

That suggests to me that we shouldn’t be allowing current to pass (leak) through our clamping diode and into IOVDD. I could be completely wrong here – if you think so then please share your thoughts in the forum (Discussions).

Anyway, to be safe we’re going to avoid that situation by sending the current to the output of one of our op-amps (LM324-sink on the schematic). The LM324 is able to sink up to ~10mA so this should work fine if we limit the current from the main op-amp (LM324-amp in the schematic). Given that the maximum voltage expected at the output of LM324-amp is around 4.5V (Vcc – 1V) then we need a resistor of at least 120R to limit the current to 10mA (4.5-3.3 / 0.010 = 120). A 220R resistor should do fine (Rout).

And of course the reason we are using an LM324 rather than the LM358 of the previous designs is that three op-amps are required.

A 1N5817 diode (D2) is used here (rather than a BAT46 – used on the input of LM354-amp) because at the expected maximum current of 10mA the forward voltage drop of the BAT46 is higher than 300mV. The high reverse current of the 1N5817 is not such an issue here because Rout has a low value and so there will only be a small voltage drop across Rout when D2 is reverse biased.

Construction

Schematic
Breadboard

Here are some instructions for assembling this front end on a breadboard. The pin numbers refer to the LM324 PDIP package. Refer to the schematic and breadboard image above. NB. The rail labelled 5V on the schematic is actually VSYS which of course is not necessarily 5V because it depends on how charged the battery is on your Android device.

Connect 3V3 of the Pico to the top red power rail of the breadboard. Connect VSYS to the bottom red power rail. Connect both ground rails of the breadboard to one of the GND pins of the Pico. The fuse as shown in the breadboard image is optional.

Connect the Vcc pin of the LM324 to the VSYS rail. Connect the GND pin of the LM324 to the GND rail. Don’t connect anything to the ADC pin(s) of the Pico yet.

Now we’ll configure each of the 4 op-amps of the LM324 in turn.

Op-amp 2 – Unused
Op-amp 2 (pins 5, 6 and 7 of the PDIP package) is not used so we’ll wire it up as recommended in the TI tech note – How to Properly Configure Unused Operational Amplifiers.

The voltage at the non-inverting input should be approximately VSYS/2 and the output should be the same.

Op-amp 4 – Vref
Wire up this op-amp as shown in the schematic. The voltage at the output should be approximately 1.65V.

Op-amp 3 – sink
Wire up this op-amp as shown in the schematic. The voltage at the output should be 3.3V.

Op-amp 1 – amp
Wire up this op-amp as shown in the schematic, including the under-voltage protection diode on the input (D1) and the current limiting resistor (Rout) and over-voltage protection diode (D2) on the output. Don’t connect the output to the Pico yet.

Testing and initial operation

You should now be able to safely apply any voltage at Vin1/Vin2 of between -18V and +18V. Test that the voltage at the input of the LM324 (Vampin) doesn’t go below -.3V and the voltage at the output of op-amp 2 after Rout (Vadc) doesn’t go above 3.6V.

Once you’ve confirmed that all of the op-amps have been wired correctly you can connect the output of Rout to the ADC pin of the Pico.


The author makes no warranty, representation or guarantees regarding the suitability of this design for any particular purpose. Nor does the author assume any liability arising out its use and specifically disclaims any and all liability, including without limitation special, consequential or incidental damages.

Designing the PCB

PCB Design and Layout

Manufacturing the PCB

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

Assembly

The PCB was assembled with help of a stencil to ease and speed up the solder paste application. The components were then hot-air soldered.
As this is only a prototype, I chose to only place 2.54mm header pins on pins that are required for operation, as well as all the ground pins, to ensure a proper ground plane.

SMD Stencil to speed up assembly

Conclusion

This was quite an interesting project. While everything works as expected, resolution and frequency are limited. ( of course, it is…) The project is however still useful, and will definitely give you some useful results in a pinch.

The logic analyser is by far more useful, but once again, a commercial device will be way more accurate and useful for professional use. Hopefully, the designer will add some protocol filters etc in future.

This device will not replace a proper oscilloscope or logic analyser, but it will definitely give enough accuracy and resolution on low-frequency applications to satisfy some of the basic needs of a beginner or student just starting out with electronics.

It is also important to note that you should be safe, and not try to connect this to high voltages etc. Also, don’t connect this to your expensive phone or tablet, use an old one instead, as accidents may happen, and we don’t want to damage our valuable handheld devices…

An Easy RP2040 Logic Analyzer Shield – Scoppy Scope Part 2

Scoppy Scope Logic analyser Shield with Logic Probes

As part two out of a series of three articles (part 1), This is the Scoppy RP2040 Logic analyzer shield, for use with our Raspberry Pi Pico Carrier board and the Scoppy Oscilloscope firmware for the RP2040.

In Part one, we took a very quick look at the installation of the firmware, as well as the basic limitations for use of this very useful project.

In this part, I want to take a quick look at my Logic Analyser shield, for use with this project, as well as the Raspberry Pi Pico Carrier Board. In part one, we saw that the logic analyzer inputs are limited to 3.3v by the RP2040 GPIO pins. This shield is a prototype attempt to overcome those limitations by using logic-level conversion.

What is on the PCB ?

The PCB is designed to be an add-on shield for the Makeriot2020 Raspberry Pi Pico Carrier Board. (Get your own here) It is in the same form factor as the Arduino Uno shields, but with pinputs specific to the RP2040 and Raspberry Pi Pico.

8 Ch Logic analyser Shield for use with Scoppy and MakerIOT2020 Pico Carrier Board

All Raspberry Pi Pico pins are broken out and labelled, as well as all of the pins specific to the Scoppy App have been clearly labelled. The board are stackable onto the Pico Carrier board, via standard 2.54mm Male Headers, or extra long, stackable female 2.45mm headers, similar to those found on common Arduino shields.

The use of stackable headers will allow simultaneous use of the logic analyser shield and the Analog frontend shield, introduced in part 3 of this series.

In addition to that, a 2×8-way 2.54mm Male header provides access to the 8 logic converted logic analyser inputs.

Logic conversion is done with a simple circuit, comprising a Bss138 N-Channel Mosfet and two 10K resistors per channel.

The shield is powered directly from the Pico Carrier board, which is in turn powered from the OTG cable to the Android Phone or tablet used to display the captured data. ( see Part 1 for installation instructions and other details regarding the Scoppy Project)

The logic level converters allow the use of a 5v logic signal, which is an improvement over the original design, which allowed only 3.3v inputs.

The Schematic and PCB Layout

Logic analyser shield schematic


PCB Layout

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.

PCBWay

Some more pictures of the device

Installation instructions (repeated from Part 1)

Scoppy Scope Installation

All credits for the development of the Scoppy firmware goes to fhdm-dev. This shield is a modification made by MakerIOT2020, and thus belongs to me. In the spirit of the original project, It will however be released to the public as a free open-source project ( free as in free download, free schematic, free design ). The PCB manufacturing files will be made available for free at a later stage, or can be ordered from PCBWay from this link

RP2040 Oscilloscope and Logic Analyser

Oscilloscopes and Logic analysers are essential instruments for every serious electronics hobbyist. They are however quite expensive, and thus beyond the reach of many people starting out with electronics. Today, I will show you a cheap solution, an RP2040 Oscilloscope and Logic analyser…

Before we get started, we need to clear up a few things first:
1). This is not my own project. It was designed and built by someone else.
2). This is not a professional grade Oscilloscope or Logic analyser
3). The range of input voltages, as well as the frequencies that you can measure, are limited.

What is this, and why do I bother with it?

This post is about the Scoppy Occiloscope Firmware, designed by fhdm-dev. I have no affiliation with him/her, I came across this recently and found it useful in the sense that it may help others gain access to instrumentation to greatly help them with electronics.

I did design some derived pcb components that works with this project, in order to take care of some limitations that I saw in the original project. More on that in two follow-up posts, in which I will show you two PCB’s that I designed to use with this project, and analog Frontend ( based on a public design by fhdm-dev, as well as a Logic analyser shield, of my own design

before we do this, we need to look at the basic Scoppy design and its firmware.

Getting Started

You will need a few things to make use of this project, the most important will be the Scoppy App ( available from the Google Playstore ), and an Android Phone.
You will also need a USB OTG Cable/hub for the phone, as well as a Raspberry Pi Pico or Pico W

The Installation and Getting Started Guide is very well documented, and as such, I will not spend a lot of time on that.

My own Setup

I have decided to use my own Raspberry Pi Pico Carrier board for this project, as it will allow me to get away from the breadboard, as well as serve as a platform for easily expanding on the project via expansion shields, as you will see in later articles.

Makeriot2020 Raspberry Pi Pico Carrier Board

This PCB, in Arduino Uno form Factor, will make putting the entire project into a case quite easy, as well as hopefully keep the number of floating hookup wires to a minimum. ( hopefully reducing some notice and other stray signals from interfering too much with our signals)

After installing the application, which is quite easy, we need to load the firmware onto the RP2040. This is also extremely easy is you follow the guide at the top.

Please note that the Android app has two modes, a freeware mode, limited to one channel, and a paid version, with no limitations. I recommend that you consider buying the paid version, as it only costs a few dollars ( I paid $USD2), and will motivate the developer to keep working on the project, and improving it.

Scoppy Application, Main Interface – Oscilloscope
Scoppy Menu
Scoppy Logic Analyser Screen

As we can see, the interface is quite clean, and easy to use.

What are the limitations?

There are quite a few limitations, namely frequency and voltage input.
From what I can understand, the frequency limit seems to be around 25Khz, with the voltage level limit being 0.0v to 3.3v ( as per the limit of the RP2040 ADC

Please make sure that you follow all instructions on the original page, as you can very easily damage your Android device as well as the Pico if you apply a voltage outside of the allowed range.

On the logic analyser side, It is also important to note that you should stay in the 0.0v to 3.3v range of the Pico GPIO’s.

While these limited ranges will definitely limit what you can do and measure, It will still be a very useful project. In the next part of this article, I will show you how I have solved the logic analyser voltage range issue… Allowing you to analyse 5v signals as well.

RaspberryPi Pico Carrier PCB

The Rp2040 chip from the RaspberryPi foundation should be quite well known to everybody by now. Many companies have also released their own development boards based on it. The original Raspberry Pi Pico is popular, based on its small size.


For myself, there is however a serious drawback, its small size, while perfect for breadboard, made it necessary for the developers to place the pinouts on the back of the board. This makes it necessary to either memorise the pinouts or always have a pinout diagram handy when working with it.

The module also comes with castellated holes, making it ideal to place onto a custom PCB as a “component”. This got me thinking, I can easily design a custom RP2040-based PCB, but manually assembling the tiny RP2040 is something that my poor eyesight will make a bit challenging (staring at computer screens for many years does really take its toll as you get older).


Finding components in stock (excluding the RP2040) is also a challenge in my area.

This made me think about taking a popular footprint ( like the Arduino Uno ), and placing a Pico module directly onto the board, labelling all the pins clearly on the front, and installing female headers to access them.

While it is obviously not a very complicated PCB, it will definitely help me to utilise the fantastic little chip more effectively.

Assembling the PCB should only take a few minutes, as you only have to solder the pico and female header pins to the board. When completed, it should look like this:

If you have already soldered headers to your Pico, you can still use this PCB as well. You can also use the new Pico W with this board, the only difference is that the Pico W does not have castellated holes on the pins, so you would have to use header-pins. Also, the debug port now has a connector, so you will have to use the port directly on the Pico for that.

A good introduction to the new Pico-W can be found here. I have not bought any yet, so have no pictures to show, or comments to make on its operation.

What is next

I have plans to start designing a series of add-on shields with specific functions for this platform, since being freed from the breadboard, the Raspberry Pi Pico suddenly became much more interesting to me.

While smaller seems to be better in the electronics world of today, breadboarding, in my humble opinion, is quite aged, and can be extremely unreliable, due to poor connections etc. It is however very quick and fast, without requiring you to solder anything.

I am thus attempting to get the best of both worlds, by not being tied down to a breadboard, but with the freedom to go there if I choose, or just designing and using a custom shield of my choosing.

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.

Easy to Use RA-02 Breakout Module

Original RA-02 breakout Module, next to improved RA-02 breakout Module

Most Makers and electronics enthusiasts may already know of the RA-02 LoRa Module. Many of them might own an RA-02 Breakout module or two… For those who do, they will surely know about the problems encountered with using this particular breakout module…

The RA-02 module, in itself, is a great piece of kit, and when used on a custom PCB, which was designed with all the little secrets of this module taken into consideration, is a pleasure. Using the RA-02 breakout module, in its existing form factor, does however present quite a few unique challenges, which, if you are unaware of them, can cause quite a few frustrating moments, or even result in permanent damage to the module…

In this post, we will focus on :
1) The Challenges of the existing commercially available RA-02 Breakout Module
2) My Solution to above mentioned Challenges
3)Testing the Module
Maker Uno – An Arduino Uno Clone
Maker Nano RP2040
Maker Pi Pico – Raspberry Pi Pico breakout module


What are these challenges:

1) The module is based on the SX1278 chip from Semtech and is a 3v device. The IO pins are NOT 5v compatible but seem to work for a few hours or so when used with 5v… This causes many people, especially on Youtube, to assume that it is ok to send 5v logic signals to this module…

I have still not seen any Youtube video telling viewers to at least use a resister divider or logic converter… People just don’t know, and those that know seem to be keeping quiet!

Adding logic converters is in fact specified by the datasheet.

2) Adding logic converters means adding additional wiring, and for a breadboard based project, that adds to the complexity.

3) You have a total of 4 ground pins that need to be connected. not connecting all of them, causes funny things to happen, from overheating down to failure… ( My personal experience while researching this project)

4) The existing breakout module is not breadboarding compatible, resulting in a floating assembly with wires going everywhere, which results in unstable connections etc…

Basically something similar to the picture below:

RA-02 breakout Module (original) with Maker Uno and Level converter module

In this picture, I have an existing RA-02 Breakout Module, with an 8 channel Logic converter and an Arduino Uno clone, along with all the needed wiring to make this setup possible… Quite a lot of wires indeed…

My solution:

I design and use quite a few LoRa PCBs and on all of them, I implement logic conversion using the BSS138 N-MOS Mosfet and 10k resistors. It is a cheap and reliable solution, but it can take up quite a lot of space on a PCB, as this means 11 Mosfets and 22 10k resistors if I were to provide level conversion to all of the RA-02’s GPIO and IO pins…

I also have the constant problem of many unnecessary wires, many of which sometimes fail straight out of the box, when prototyping something. I partly solved that by designing a few dedicated PCB solutions, but that is not always ideal,

Using a dedicated Logic Converter IC, and Mosfet based converters to make up the difference, on a breadboard compatible module, seemed like a good idea, so I went ahead and designed the following solution:

RA-02 breakout Module on a breadboard

The breakout board module is breadboard compatible, and also has clearly marked pins to indicate the 3v and 5v sides of the module.

Testing the Module:

Using a 5v device ( Cytron’s Maker Uno )

For my first test, I decided to test with an Arduino Uno Clone, since that is what most Makers and students will have access to. I used Cytron’s Maker Uno platform, which is equipped with some added goodies, in the form of diagnostic LED etc to make prototyping a lot easier.

RA-02 breakout Module, connected to Maker Uno

As we can clearly see, It is only necessary to connect to the 5v logic side of the module, as well as provide 3v and 5v + GND to the module

In this test, I used Sandeep Mistry’s LoRa Library, with the Arduino IDE to do a quick test sketch.

Connections are as follows:

RA-02 Module Maker Uno

MISO D12

MOSI D11

SCK D13

NSS D10

RST D9

DIO0 D2

OE D8

Full code download

Let us look at some important sections though, to thoroughly understand how to use the module:

Pin Declaration

#include <SPI.h>       // include libraries

#include <LoRa.h> // I used Sandeep Mistry’s LoRa Library, as it is easy to use and understand

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

const int OEPin = 8;     // Output Enable Pin, to enable the Logic Converter

In the Setup function, we need to do a bit of extra work, since our Maker Uno ( or your Arduino Uno ) is a 5v device…

void setup() {

 Serial.begin(115200); // initialize serial

 pinMode(OEPin,OUTPUT); // Setup the OE pin as an Outout

 digitalWrite(OEPin,HIGH); // and Pull it High to enable the logic converter

 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.”);

}

A comparison, using the standard RS-02 Breakout module, together with one of my own “Arduino type PCB”

ATMEGA328P with 8 Channel Logic Converter.

Original RA-02 Breakout Module, connected to an ATMEGA328P PCB with onboard Level converters

As we can see, you need quite a lot more wires to make this work. It is also worth noting that we have only 8 level converters on this ATMEGA328P PCB, in order to use all of the RA-02’s GPIO, we will need to add an additional external logic converter as well.

Using a 3v Device:

Cytron’s Maker Nano RP2040

For my second test, I decided to be a bit brave, and try to use the new Raspberry Pi Pico ( RP2040 Microprocessor ). I have quite a few of them lying around and have never really done a lot with them, due to the fact that I do not really like using MicroPython or CircuitPython, and also because the recently released Arduino Core for the RP2040 still being quite new… I decided to use a development board that I recently bought from Cytron, the Maker Nano RP2040, as it has all the added diagnostic features to make my life a bit easier, I will also include a test with an original Pi Pico board, to make it more accessible to everyone out there.

RA-02 Breakout Module, connected to Maker Nano RP2040

Once again, I used Sandeep Mistry’s LoRa Library, with the exact same Arduino sketch, used for the Maker Uno test. (I obviously needed to change the pin numbers though, as the RP2040 uses different pins for its SPI interface).

Maker Nano RP2040 RA-02 Breakout Module

NSS 17

MOSI 19

MISO 16

SCK 18

RST 9

DIO0 8

In this case, we DO NOT need the OE pin, as the RP2040 is a native 3v device. The level converter can thus stay disabled, with its pins in tri-state ( high impedance ) mode.

If we look at the code, it is similar to the Maker Uno’s code, with only the Pin declarations needing a change

#include <SPI.h>       // include libraries

#include <LoRa.h>

const int csPin = 17;     // LoRa radio chip select

const int resetPin = 9;    // LoRa radio reset

const int irqPin = 8;     // 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

// Note that SPI has different names on the RP2040, and it has 2 SPI ports. We used port 0

// CIPO (Miso) is on pin 16

// COPI (Mosi) is on pin 19

// SCK is on pin 18

// CE/SS is on pin 17, as already declared above

I did not use a breadboard, in order to make things as easy as possible.

Cytron’s Maker Pi Pico – A Pi Pico on a breakout PCB

RA-02 Breakout Module, connected to Maker Pi Pico

To make things a bit easier, without having to resort to using a breadboard, I decided to do the Original Pi Pico test using the Maker Pi Pico PCB. This PCB is basically a big breakout module, with detailed pin numbers and some diagnostic LEDs, but it also uses a native Pi Pico, soldered directly to the PCB, by means of the castellated holes… So, While technically not being a true standalone Pico, It makes my life easier and was thus used for the test, as I can be sure that the pins are labelled exactly the same as on the original Pico.

The code used for the Maker Nano RP2040 works perfectly, with no changes required.

This post is getting quite long by now, so I have decided not to include my tests of the ESP-12E ( NodeMCU ) or ESP32 development boards here as well… They also function as expected.

In Summary

When I started this project, I set out to solve a problem ( personal to me ), that could potentially help a lot of other people use the RA-02 Module for more projects and tasks. The Breakout module in its current form can also be used with the RA-01h module (915Mhz Module) without any changes. All GPIO pins are broken out, and accessible through full logic converted pins on both sides of the breakout module.

I hope that this will be useful to someone. I am also not releasing the full schematics at this stage, as I may decide to make some minor cosmetic changes in the near future.

The PCB can however be ordered from PCBWay in its current form and works 100% as expected. The BOM file is available with the ordered PCB as usual.

PCBWay Banner

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,

PCBWay Start Quotation Page

4) Click on PCB Instant Quote

PCBWay Instant Quote

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

Quick order PCB from PCBWay

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.

PCBWay PCB parameters
PCBWay PCB Parameters - Page 2

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 ).

PCBWay Stencil
PCBWay Checkout

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.

Simplifying Robotics with Raspberry Pi® RP2040

Introducing the Cytron Maker RP2040

Cytron Maker Pi RP2040 features the first microcontroller designed by Raspberry Pi – RP2040, embedded on a robot controller board. This board comes with a dual-channel DC motor driver, 4 servo motor ports and 7 Grove I/O connectors, ready for your next DIY robot/motion control project. Now you can build a robot while trying out the new RP2040 chip.

 

The DC motor driver on board is able to control 2x brushed DC motors or 1x bipolar/unipolar stepper motor rated from 3.6V to 6V, providing up to 1A current per channel continuously. The built-in Quick Test buttons and motor output LEDs allow a functional test of the motor driver in a quick and convenient way, without the need of writing any code. Vmotor for both DC and servo motors depends on the input voltage supplied to the board.


Credit: 3D robot parts designed by Camilo Parra Palacio from OttoDIY Community.
 


Credit: Self-watering Planter 3D parts on Thingiverse.
 

Maker Pi RP2040 features all the goodness of Cytron’s Maker series products. It too has lots of LEDs useful for troubleshooting (& visual effects), is able to make quite some noise with the onboard piezo buzzer and comes with push buttons ready to detect your touch.

There are three ways to supply power to the Maker Pi RP2040 – via USB (5V) socket, with a single cell LiPo/Li-Ion battery or through the VIN (3.6-6V) terminals. However, only one power source is needed to power up both controller board and motors at a time. Power supply from all these power sources can all be controlled with the power on/off switch onboard.

Cytron Maker Pi RP2040 is basically the Raspberry Pi Pico + Maker series’ goodness + Robot controller & other useful features. Therefore this board is compatible with the existing Pico ecosystem. Software, firmware, libraries and resources that are developed for Pico should work seamlessly with Cytron Maker Pi RP2040 too.

CircuitPython is preloaded on the Maker Pi RP2040 and it runs a simple demo program right out of the box. Connect it to your computer via USB micro cable and turn it on, you will be greeted by a melody tune and LEDs running light. Press GP20 and GP21 push buttons to toggle the LEDs on/off while controlling any DC and servo motors connected to it to move and stop. With this demo code, you get to test the board the moment you receive it!

While connected to your computer, a new CIRCUITPY drive appears. Explore and edit the demo code (code.py & lib folder) with any code editor you like, save any changes to the drive and you shall see it in action in no time. That’s why we embrace CircuitPython – it’s very easy to get started. Wish to use other programming languages? Sure, you are free to use MicroPython and C/C++ for Pico/RP2040. For those of you who love the Arduino ecosystem, please take a look at this official news by Arduino and also the unofficial Pico Arduino Core by Earle F. Philhower.

Features:

  • Powered by Rapberry Pi RP2040
    • Dual-core Arm Cortex-M0+ processor
    • 264KB internal RAM
    • 2MB of Flash memory
    • the exact same specifications with Raspberry Pi Pico
  • Robot controller board
    • 4x Servo motors
    • 2x DC motors with quick test buttons
  • Versatile power circuit
    • Automatic power selection: USB 5V, LiPo (1-cell) or Vin (3.6-6V)
    • Built-in 1-cell LiPo/Li-Ion charger (over-charged & over-discharged protection)
    • Power on/off switch
  • 13x Status indicator LEDs for GPIO pins
  • 1x Piezo buzzer with mute switch
  • 2x Push button
  • 2x RGB LED (Neopixel)
  • 7x Grove ports (flexible I/O options: digital, analog, I2C, SPI, UART…)
  • Preloaded with CircuitPython by default
  • Mouting holes
    • 4x 4.8mm mounting hole (LEGO® pin compatible)
    • 6x M3 screw hole

Maker Pi RP2040 VS. Maker Pi Pico?


Board Layout:

Dimension:

88mm(L) x 64mm(W) x 13mm(H)

Packing List:

Resources:

Introducing Maker Pi RP2040

Cytron Technologies has done it again, this time by releasing an in-house designed complete robotics controller board, based on the brand new RP2040 MCU from the Raspberry Pi Foundation.

This post will be part one of a detailed look at this new product.. So, as it is an introduction, lets get some technical specs and features…

Features:

  • Powered by Rapberry Pi RP2040
    • Dual-core Arm Cortex-M0+ processor
    • 264KB internal RAM
    • 2MB of Flash memory
    • the exact same specifications with Raspberry Pi Pico
  • Robot controller board
    • 4x Servo motors
    • 2x DC motors with quick test buttons
  • Versatile power circuit
    • Automatic power selection: USB 5V, LiPo (1-cell) or Vin (3.6-6V)
    • Built-in 1-cell LiPo/Li-Ion charger (over-charged & over-discharged protection)
    • Power on/off switch
  • 13x Status indicator LEDs for GPIO pins
  • 1x Piezo buzzer with mute switch
  • 2x Push button
  • 2x RGB LED (Neopixel)
  • 7x Grove ports (flexible I/O options: digital, analog, I2C, SPI, UART…)
  • Preloaded with CircuitPython by default
  • Mouting holes
    • 4x 4.8mm mounting hole (LEGO® pin compatible)
    • 6x M3 screw hole



Cytron Maker Pi RP2040 features the first micro-controller designed by Raspberry Pi – RP2040, embedded on a robot controller board. The board also comes with dual channel DC motor driver, 4 servo motor ports and 7 Grove I/O connectors, ready for your next DIY robot / motion control project. Now you can build robot, while trying out the new RP2040 chip.

The DC motor driver onboard is able to control 2x brushed DC motors or 1x bipolar/unipolar stepper motor rated from 3.6V to 6V, providing up to 1A current per channel continuously. The built-in Quick Test buttons and motor output LEDs allow functional test of the motor driver in a quick and convenient way, without the need of writing any code. Vmotor for both DC and servo motors depends on the input voltage supplied to the board.

ker Pi RP2040 features all the goodness of Cytron’s Maker series products. It too has lots of LEDs useful for troubleshooting (& visual effects), is able to make quite some noise with the onboard piezo buzzer and comes with push buttons ready to detect your touch.

There are three ways to supply power to the Maker Pi RP2040 – via USB (5V) socket, with a single cell LiPo/Li-Ion battery or through the VIN (3.6-6V) terminals. However only one power source is needed to power up both controller board and motors at a time. Power supply from all these power sources can all be controlled with the power on/off switch onboard.

Cytron Maker Pi RP2040 is basically the Raspberry Pi Pico + Maker series’ goodness + Robot controller & other useful features. Therefore this board is compatible with the existing Pico ecosystem. Software, firmware, libraries and resources that are developed for Pico should work seamlessly with Cytron Maker Pi RP2040 too.

CircuitPython is preloaded on the Maker Pi RP2040 and it runs a simple demo program right out-of-the-box. Connect it to your computer via USB micro cable and turn it on, you will be greeted by a melody tune and LEDs running light. Press GP20 and GP21 push buttons to toggle the LEDs on/off, while controlling any DC and servo motors connected to it to move and stop. With this demo code, you get to test the board the moment you receive it!


 Out-of-the-box Demo for Cytron Maker Pi RP2040
  
 This demo code is written in CircuitPython and it serves
 as an easy quality check when you first receive the board.
 #
 It plays a melody upon power up (slide power switch to ON)
 and shows running lights (blue LEDs) at the same time.
 Then the two RGB LEDs will animate the colors, while the
 program checking push buttons' state, repeatedly.
  
 Press GP20 button to play a short melody, lights up all
 blue LEDs, move servo motors to 0 degree and run DC motors
 at 50% and -50% speeds.
 Press GP21 button to play another melody, turn off all blue
 LEDs, move servo motors to 180 degree & brake DC motors.
  
 Maker Pi RP2040 also has four DC motors quick test buttons
 built-in. You may press the onboard M1A, M1B, M2A or M2B
 push buttons to run your motors without writing any code.
 #
 More info:
 http://www.cytron.io/p-maker-pi-rp2040
 https://circuitpython.org/board/raspberry_pi_pico
 #
 Email: support@cytron.io
 *
 import board
 import digitalio
 import neopixel
 import simpleio
 import time
 import pwmio
 from adafruit_motor import servo, motor
 Initialize LEDs
 LEDs placement on Maker Pi RP2040
 LED_PINS = [board.GP0, 
             board.GP1,
             board.GP2,
             board.GP3,
             board.GP4,
             board.GP5,
             board.GP6,
             board.GP7,
             board.GP16,
             board.GP17,
             board.GP26,
             board.GP27,
             board.GP28]
 LEDS = []
 for pin in LED_PINS:
     # Set pins as digital output
     digout = digitalio.DigitalInOut(pin)
     digout.direction = digitalio.Direction.OUTPUT
     LEDS.append(digout)
 Initialize Neopixel RGB LEDs
 pixels = neopixel.NeoPixel(board.GP18, 2)
 pixels.fill(0)
 Melody
 MELODY_NOTE = [659, 659, 0, 659, 0, 523, 659, 0, 784]
 MELODY_DURATION = [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.2]
 Define pin connected to piezo buzzer
 PIEZO_PIN = board.GP22
 Initialize buttons
 btn1 = digitalio.DigitalInOut(board.GP20)
 btn2 = digitalio.DigitalInOut(board.GP21)
 btn1.direction = digitalio.Direction.INPUT
 btn2.direction = digitalio.Direction.INPUT
 btn1.pull = digitalio.Pull.UP
 btn2.pull = digitalio.Pull.UP
 Initialize servos
 50% duty cycle: 2**15 = 32768 = 1/2 of 65536 (16-bit)
 servo_motors = []  # create an array and add servo objects.
 servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP12, duty_cycle=215, frequency=50))) servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP13, duty_cycle=215, frequency=50)))
 servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP14, duty_cycle=215, frequency=50))) servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP15, duty_cycle=215, frequency=50)))
 Initialize DC motors
 m1a = pwmio.PWMOut(board.GP8, frequency=50)
 m1b = pwmio.PWMOut(board.GP9, frequency=50)
 motor1 = motor.DCMotor(m1a, m1b)
 m2a = pwmio.PWMOut(board.GP10, frequency=50)
 m2b = pwmio.PWMOut(board.GP11, frequency=50)
 motor2 = motor.DCMotor(m2a, m2b)
 -------------------------------------------------
 ON START: Show running light and play melody
 -------------------------------------------------
 for i in range(len(LEDS)):
     LEDS[i].value = True
 if i < len(MELODY_NOTE):     # Play melody tones     simpleio.tone(PIEZO_PIN, MELODY_NOTE[i], duration=MELODY_DURATION[i]) else:     # Light up the remainding LEDs     time.sleep(0.15)
 Turn off LEDs one-by-one very quickly
 for i in range(len(LEDS)):
     LEDS[i].value = False
     time.sleep(0.02)
 color = 0
 state = 0
 -------------------------------------------------
 FOREVER LOOP: Check buttons & animate RGB LEDs
 -------------------------------------------------
 while True:
 # Check button 1 (GP20) if not btn1.value:  # button 1 pressed     # Light up all LEDs     for i in range(len(LEDS)):         LEDS[i].value = True     # Move servos to 0 degree     for i in range(len(servo_motors)):         servo_motors[i].angle = 0     # Move motors at 50% speed     motor1.throttle = 0.5  # motor1.throttle = 1 or -1 for full speed     motor2.throttle = -0.5     # Play tones     simpleio.tone(PIEZO_PIN, 262, duration=0.1)     simpleio.tone(PIEZO_PIN, 659, duration=0.15)     simpleio.tone(PIEZO_PIN, 784, duration=0.2) # Check button 2 (GP21) elif not btn2.value:  # button 2 pressed     # Turn off all LEDs     for i in range(len(LEDS)):         LEDS[i].value = False     # Move servos to 180 degree     for i in range(len(servo_motors)):         servo_motors[i].angle = 180     # Brake motors     motor1.throttle = 0  # motor1.throttle = None to spin freely     motor2.throttle = 0     # Play tones     simpleio.tone(PIEZO_PIN, 784, duration=0.1)     simpleio.tone(PIEZO_PIN, 659, duration=0.15)     simpleio.tone(PIEZO_PIN, 262, duration=0.2) # Animate RGB LEDs if state == 0:     if color < 0x101010:         color += 0x010101   # increase rgb colors to 0x10 each     else:         state += 1 elif state == 1:     if (color & 0x00FF00) > 0:         color -= 0x000100   # decrease green to zero     else:         state += 1 elif state == 2:     if (color & 0xFF0000) > 0:         color -= 0x010000   # decrease red to zero     else:         state += 1 elif state == 3:     if (color & 0x00FF00) < 0x1000:         color += 0x000100   # increase green to 0x10     else:         state += 1 elif state == 4:     if (color & 0x0000FF) > 0:         color -= 1          # decrease blue to zero     else:         state += 1 elif state == 5:     if (color & 0xFF0000) < 0x100000:         color += 0x010000   # increase red to 0x10     else:         state += 1 elif state == 6:     if (color & 0x00FF00) > 0:         color -= 0x000100   # decrease green to zero     else:         state += 1 elif state == 7:     if (color & 0x00FFFF) < 0x001010:         color += 0x000101   # increase gb to 0x10     else:         state = 1 pixels.fill(color)  # fill the color on both RGB LEDs # Sleep to debounce buttons & change the speed of RGB color swipe time.sleep(0.05)

Maker Pi RP2040 VS. Maker Pi Pico?

Arduino Support for the Pi Pico …

Official Arduino IDE support for the Raspberry Pi Pico is finally here. It took a while,and those of us that could not be bothered with Micro-Python, or complex C tool-chains, can finally take out Pico’s out of the drawer, and start putting them through their paces…

This is also an excellent opportunity to really push the Maker Pi Pico, from Cytron Technologies, so its limits, as the rich library environment from the Arduino IDE, will definitely allow quick and fast access to all of the Maker Pi Pico’s built in hardware…



Adding Pico Support to the Arduino IDE

Before we can use the Pico with the Arduino IDE, we first have to add support for the board into the Arduino IDE.
This is done with the Boards Manager, Although very easy, there are however a few things that you have to take note of. You have to remove support for ALL other Pi Pico boads packages that you may have installed into the Arduino IDE, previously, as well as any additional board url’s in the preferences menu…

Then, after removing that all, restart your Arduino IDE, go to the Tools menu, and then Boards _> Boards Manager.
Type Pico into the search box. Press Enter…

Select and Install the “Arduino MBed OS RP2040 Boards”…
Wait for this to install, It will take a while, depending on your internet speed…

When this is finished, we can configure your Pico board.

Please Note:
On Linux operating systems, like Ubuntu, you will have to perform an additional step. This is because of permissions on hardware devices. You will have to start the Arduino IDE as a superuser, i.e. with sudo, from the command line, and then install the RP2040 support AS WELL…. Once that is done, keep the IDE open, and continue with the rest of this guide….

To do this do the following:

Open a Terminal Window
go to the Arduino installation folder, on my system ( Ubuntu 20.04 LTS it is /home/jean/Downloads/arduino-1.8.13 )
and then issue the command $ sudo ./arduino

You will get a similar display as above …
Now open the boards manager again, and install the “Arduino MBed OS RP2040 Boards” board support files ….

Continue to the next step below…

Uploading your first sketch to the Pico

DO NOT PLUG THE PICO INTO A USB PORT YET

With the Arduino IDE Open, ( As superuser on Ubuntu or other Linux), open a blank sketch, and select the Raspberry Pi Pico, from the Boards menu under Tools ( It will be under Arduino MBed OS RP2040)

Open a blank sketch, or the standard blink example sketch.

Now, while holding the BOOTSEL button on the PICO pressed in, plug in your PICO, and then release the button.
The Pico will open a File Dialog on your computer, similar to when you loaded Micro-Python Support.
Do NOT search for a Com port at this stage, it will not exist yet !

Ignore the File window, and click on the upload button in the Arduino IDE.
The sketch will upload, and the PICO will reset automatically.

UBUNTU or other Linux Users, If this was successful, you can close the Arduino IDE as superuser, and open your standard Arduino IDE.

After this step, you will not have to hold down BOOTSEL every time to upload a sketch, even if you have unplugged the PICO, but you will have to select a valid COM port in the Arduino IDE… On Ubuntu, it will be /dev/ttyACM0 or similar, please look in the ports menu under tools in the Arduino IDE.

You can now make use of all the existing Arduino libraries with your Raspberry Pi Pico…

A few points to note:

I2C is on GP6 (SCL) and GP7 (SDA) -> confirmed as definitely working ( i2c1, not i2c0 !)
SPI is as mentioned in this post -> GitHUB ( Please note that there seem to still be a bit of teething problems, your mileage may vary )

Maker Pi Pico with ESP01S Module

It has been a while since my last post, most of which has been spent dealing with other things, as well as waiting for electronics modules to arrive from overseas. A lot of my time has also been spent on getting to grips with the Raspberry Pi Pico, and in particular, the Maker Pi Pico, from Cytron Technologies. This has been an experience with quite a lot of mixed feelings… As Usual, Cytron has done an excellent job with the development board, which, while apparently still in Beta, seems to be rock solid. Most of my frustration came from the “patchy” C/C++ support for the Pi Pico (Yes, I know there are great support, BUT it is not exactly user friendly 🙂 ). That left me with MicroPython, which although I am fluent, are not my goto language…

Lets get back on track though… The Maker Pi Pico has built in support for an ESP01/ESP01S Module. Lets look at the schematic….

Maker Pi Pico Schematic

As we can see, Cytron has provided us with access to Tx (GP17) and Rx(GP16) directly on the Pi Pico. Power (+3.3v) and Ground are connected as well… On this version of the board, no access to IO0,IO2 and the Reset Pin for the ESP01/ESP01S was provided… Maybe this will change in future…?

I have used the standard AT command firmware that comes pre-loaded onto the ESP01/S module. This allows you to send AT commands to the ESP01 Module to control it. It is also possible to setup a transparent WiFi “channel” to communicate between Pico and a remote application , making it possible to control Pico remotely. I have however not prepared and example of that for release yet….

MicroPython Code to communicate with ESP01 from Maker Pi Pico

import uos
from machine import UART, Pin
import utime

"""
ESPRESSIF AT Command Set
https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/
"""

print()
print("Machine: \t" + uos.uname()[4])
print("MicroPython: \t" + uos.uname()[3])

#indicate program started visually
led_onboard = machine.Pin(25, machine.Pin.OUT)
led_onboard.value(0)     # onboard LED OFF/ON for 0.5/1.0 sec
utime.sleep(0.5)
led_onboard.value(1)
utime.sleep(1.0)
led_onboard.value(0)

uart0 = UART(0, rx=Pin(17), tx=Pin(16), baudrate=115200)
# NOTE that we explicitly set the Tx and Rx pins for use with the UART
# If we do not do this, they WILL default to Pin 0 and Pin 1
# Also note that Rx and Tx are swapped, meaning Pico Tx goes to ESP01 Rx 
# and vice versa.
print(uart0)

def sendCMD_waitResp(cmd, uart=uart0, timeout=2000):
    print("CMD: " + cmd)
    uart.write(cmd)
    waitResp(uart, timeout)
    print()
    
def waitResp(uart=uart0, timeout=2000):
    prvMills = utime.ticks_ms()
    resp = b""
    while (utime.ticks_ms()-prvMills)<timeout:
        if uart.any():
            resp = b"".join([resp, uart.read(1)])
    print("resp:")
    try:
        print(resp.decode())
    except UnicodeError:
        print(resp)
    
sendCMD_waitResp('AT\r\n')          #Test AT startup
sendCMD_waitResp('AT+GMR\r\n')      #Check version information
#sendCMD_waitResp('AT+RESTORE\r\n')  #Restore Factory Default Settings
sendCMD_waitResp('AT+CWMODE?\r\n')  #Query the Wi-Fi mode
sendCMD_waitResp('AT+CWMODE=1\r\n') #Set the Wi-Fi mode = Station mode
sendCMD_waitResp('AT+CWMODE?\r\n')  #Query the Wi-Fi mode again
#sendCMD_waitResp('AT+CWLAP\r\n', timeout=10000) #List available APs
sendCMD_waitResp('AT+CWJAP="jean_iot","master123abc"\r\n', timeout=5000) #Connect to AP
utime.sleep(1)
sendCMD_waitResp('AT+CIFSR\r\n')    #Obtain the Local IP Address

You can now extend and adapt this code to suit your purposes…

The ESP01/ESP01S AT Command Datasheet is available for download here

Thank you