Porting python functionality to pi pico

I would like to have a Raspberry Pi Pico send serial messages to the radio. I do not think the pico has enough storage or serial compatibility out of the box to implement the meshtastic library directly.

My goal is to put a series of buttons on a pico and interface it usb/usb to the node where I push a button on the pico, it sends a message to the radio. I know that the canned message module exists and does this already, though there are a few reasons I’m trying this, not the least of which because it’s a challenge but mostly given the environment where this will be used (incredibly high light with the need for incredibly simple input to reduce errors in a really distracting environment).

Right now I’m building it locally, trying to brute force the equivalent of interface.sendText(“asdfoo”) from a python script.

serialPort = serial.Serial(port = "/dev/cu.wchusbserial51850266181", baudrate=921600,
                           bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE)

def getPacket(text):
    x = {'to': 0xffffffff,'want_ack': False,'hop_limit': 3,'channel':0,'payload': text,'portnum': 'TEXT_MESSAGE_APP','want_response': False,'id': 46834053}
    return x
    
def sendText(text):
    print(text)
    meshPacket = getPacket(text)
    #json_object = json.dumps(meshPacket, indent = 0)
    print(bytes(str(meshPacket),'utf-8'))
    serialPort.write(str(meshPacket).encode('utf-8'))

sendText("asdfoo")

>>> output
   asdfoo
   b"{'to': 4294967295, 'want_ack': False, 'hop_limit': 3, 'channel': 0, 'payload': 'asdfoo', 'portnum': 
   'TEXT_MESSAGE_APP', 'want_response': False, 'id': 46834053}"

I am pretty sure that 1) I don’t have the exact message format and 2) the encoding might be off. I took the example from the mesh_interface.py as best I could. Any thoughts on this?

The message passing between the Python API and the radios is done using protobufs. If you piggyback off of the code in the python CLI to generate the protobuf packet what you’re doing should work.

That is part of the problem. Getting the google protobuf module on the pico is the challenge. I’ll take that query to the pico community.

Nanopb is the specific embedded version used

I realized, after getting nanopb working in C, that the setup won’t work w/o making the pico a USB host. I might consider that in the future though it’s a whole can of worms I’m not about to open.

Thanks for the pointers.

Our next version has some serial / uart features on the roadmap that could work well with some of the PICO’s graphics features.

1 Like