I have been experimenting with the Radxa X2L One of the conclusions I have come to is the Picomite Basic firmware is easier to work with on an RP2040 than MircoPython or Circuit Python. I am aware that the Basic programing language is not exactly in vogue these days and Python is superior in almost every way, but really no programing language beats Basic for rapid prototyping. On top of that, I really do like this Basic implementation, it keeps a lot of what made the old 1980's Basic fun, while adding modern features.
https://geoffg.net/picomite.html
To keep everything in line, I also opted to use FreeBasic on the Intel side of this system. FreeBasic is a pretty good implementation of the Basic language and even has some switches to make it compatible with old Basic code.
This project is going to show you how to use FreeBasic to retrieve the IP address of your system in Linux, then transmit your IP address to the RP2040, which will then use Picomite MMBasic to display the data on a SSD1309 OLED. This is useful for systems in a DHCP environment IP addresses change frequently. You could also use this method to display CPU temperatures or even a joke of the day.
The first thing you will need to do is flash the firmware into the RP2040, this is covered in the Picomite documentation and a dozen or so Youtube video, so I will not go over it. The second thing you will need to do is wire your OLED to the RP2040 GPIO pins. Again, there are plenty of tutorials about how to do this.
Next you will need to connect to the RP2040 through the serial port. I use Minicom in Linux
minicom -D /dev/ttyACM0
Finally before we can start programming, we need to configure the Picomite software to use I2C and the SSD1306 OLED. You do this by typing the following two lines into your terminal program, you will only have to do this once.
OPTION SYSTEM I2C GP2, GP19
OPTION LCDPANEL SSD1306I2C, LANDSCAPE
The GP2 and GP19 switches tell the software what wires you are using for communication, if you are using different GPIO pins, you will need to adjust your command appropriately. The first one is the SDA pin, the second is the SCL pin.
Now, in your terminal, type edit and press enter. This will open the built in text editor. Go a head and type this program in.
'RP2040.BAS
CLS
Box 0, 0, 128, 64, 2, RGB(WHITE), RGB(BLACK)
Text 10, 10, "Connected", "L", 1, 1, RGB(WHITE), RGB(BLACK)
Input "IP Address: ", ipaddr$
Text 10, 20, ipaddr$, "L", 1, 1, RGB(WHITE), RGB(BLACK)
The first line is simply a comment stating the name of the program. I do this because when you save a program to the flash memory, it automatically names it whatever is in the first line. Doing this makes it easy to identify which is which.
The next five lines;
- Clear the OLED screen
- Draws a framing box around the edge of the display
- Writes "Connected" to the screen
- It then waits for input
- Once it receives input, it writes that input to the OLED.
Once you have typed in the program, or done a copy/paste, press the F1 key to save it. Next type "FLASH SAVE 1", This will save the program to the build in storage, so it can be retrieved later. Lastly, you will want to type "run", you should see is waiting for input, leave it be.
Now open a new terminal, if you have not installed FreeBasic, you should do so now. Type "nano intel.bas" and enter this program.
dim as string ipaddr
open pipe "for input as #1ip -4 addr show | grep wl* | grep -oP '(?<=inet\s)\d+(\.\d+){3}'"
line input #1, ipaddr
close #1
open "/dev/ttyACM0" for output as #1
print #1, ipaddr
close #1
Each line of this program
- Defines the variable ipaddr as a string
- Runs a shell command to retrieve the IP address of the system
- Sets the ipaddr variable to the IP address of the system
- Closes the pipe used for running the shell command
- Opens the serial port so it can be written to
- Transmits the ipaddr variable to the RP2040
- Closes the serial port
Once the program has been written, press Ctrl-x, press Y and then enter. This will save the program. To compile the program, type "fbc intel.bas", you should now have an intel executable, simply type "./intel" and press enter. If all went well, you should see the IP address appear in the minicom terminal and on the OLED.
If you want this to run each time the system boots up, type "OPTION AUTORUN 1" into the minicom terminal. This will tell the RP 2040 to run the program in slot 1 on boot up. Then copy the intel executable to /usr/local/bin and add it to you startup programs.
That is pretty much it. You will still have two slots on the RP2040 to save other programs. This is a pretty good start to making the RP2040 useful to you when using the Radxa X2L. I kind of feel like all computers should have an RP2040 built in.