Radxa X2L: A Mini PC and a Raspberry Pi Crossover
The Radxa X2L SBC is a Mini PC that wants to be a single board computer. It has an Intel X86 CPU, the J4125, and an onboard Raspberry Pi RP2040 microcontroller chip.
Hardware Overview
I go into a lot of detail on how the XL2 works and compare it to other SBCs and Mini PCs.
RP2040 Microcontroller
Most notably, the X2L has a piece of Raspberry Pi onboard. The GPIO on the X2L is not controlled by the Intel chip but rather the RP2040 microcontroller chip. The RP2040 is independent from the main Intel CPU but they are connected to each other via serial interface.
This means, in order for the Intel chip to get inputs from GPIO, you need to set up serial communication in your RP2040 script.
Here is an example using CircuitPython on the RP2040 taking advantage of the serial communication with the Intel chip. This is the sample code that will run on the RP2040.
import board
import busio
import adafruit_mcp9600
import sys
import json
i2c = busio.I2C(board.GP27, board.GP22, frequency=100000)
mcp = adafruit_mcp9600.MCP9600(i2c)
while True:
v = sys.stdin.readline().strip()
jme = json.loads(v)
print(jme)
if jme['action'].lower() == "temp":
print(mcp.temperature)
else:
print("This is a test")
On the Intel side, this is the code sending a signal to the RP2040 requesting it to read the temperature from the sensor every two seconds.
import serial
import time
s = serial.Serial("/dev/ttyACM0", 115200)
while True:
s.write(b"{\"action\":\"temp\"}\n")
time.sleep(2)
An interesting feature is that you can virtually reboot the RP2040 and also virtually put it in BOOTSEL mode to flash new firmware using the Intel GPIO. GPIO 60 on the Intel chip can ground the RUN pin on the RP2040 and GPIO 61 on the Intel chip can be used to put the RP2040 in BOOTSEL mode.
A script like this will put the RP2040 in BOOTSEL mode.
#! /bin/bash
sudo gpioset gpiochip1 60=1
sudo gpioset gpiochip1 61=1
sleep 1
sudo gpioset gpiochip1 60=0
sudo gpioset gpiochip1 61=0
To simply reboot the RP2040 – useful when a script crashes – use GPIO 60 to short the RUN pin on the RP2040 to ground.
#! /bin/bash
sudo gpioset gpiochip1 60=1
sleep 1
sudo gpioset gpiochip1 60=0
I modified your code for MicroPython, using the built in temperature sensor , it also displays Fahrenheit. This gives dumb temperature readings because the location of the sensor, but it does work.
import machine
import time
import json
import sys
adcpin = 4
sensor = machine.ADC(adcpin)
def ReadTemperature():
adc_value = sensor.read_u16()
volt = (3.3/65535) * adc_value
temp_c = 27 – (volt – 0.706)/0.001721
return round(temp_c, 1)
while True:
v = sys.stdin.readline().strip()
jme = json.loads(v)
if jme[‘action’].lower() == “temp”:
temp_c = ReadTemperature()
temp_f = temp_c * (9 / 5) + 32
print(temp_c, “C /”, temp_f, “F”)
else:
print(“This is a test”)