Tuesday, June 18, 2024

Radxa X2L Single Board Computer Part 2

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.

 https://www.freebasic.net/

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;

  1. Clear the OLED screen
  2. Draws a framing box around the edge of the display
  3. Writes "Connected" to the screen
  4. It then waits for input
  5. 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

  1. Defines the variable ipaddr as a string
  2. Runs a shell command to retrieve the IP address of the system
  3. Sets the ipaddr variable to the IP address of the system
  4. Closes the pipe used for running the shell command
  5. Opens the serial port so it can be written to
  6. Transmits the ipaddr variable to the RP2040
  7. 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.

 

Saturday, June 1, 2024

Garbage Terminal: Part 3

 

So, I have this more or less built out, at least in its draft form. The 3D printing process did not go particularly well, which is not a surprise, I have a cheap printer and a very drafty house, so getting a good clean print is rather difficult. However, for version 0.95 I am not going to complain much. It pretty much does what I need it to do and it was built entirely out of parts I had on hand.

The first question of course, is it usable? Well, yes, however is it practical? No. Honestly I would not try to do any meaningful work on this terminal at all. It does not feel comfortable to hold, nor does the keyboard feel right. and the screen is too small for my old eyes.

On top of the feel, the Raspberry Pi Zero is just not designed to be useful in this sort of capacity. The CPU is too slow and the memory is too limited. If I were buying the parts for this today, I would have went for a Raspberry Pi 4 or 5 and a much better miniature keyboard, but even then I am not sure it would be terribly useful for anything, even with a GUI and a touchscreen.

Of course this also leads me to wonder if buying a professionally built hand terminal would be all that useful too me either. There is nothing this can do that a laptop can't do or heck, a bit of hacking and my phone could do most of it. Both of those options would be more useful and more comfortable to use. So yeah, realistically I think I will pass on the idea of a hand terminal.


Mastodon