this post was submitted on 30 Jul 2024
24 points (100.0% liked)

Linux

48069 readers
1025 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

This is something that perplexed me a few years ago with Flash Forth on a PIC18/PIC24/Arduino Uno. I was using the Python serial emulator S-Term because it is simple in the source code and worked. I really wanted a way to load more structured Words into the FF dictionary with bookmarks in a way that made sense structurally. That lead to a desire to execute code from the uC on the host system, but I never wrapped my head around how to do this in practice.

As a random simple example, let's say I set up an interrupt based on the internal temperature sensor of the PIC18. Once triggered the uC must call a Python script on the host system and this script defines a new FF word on the uC by defining the Word in the interpreter.

How do you connect these dots to make this work at the simplest 'hello world' level? I tried modifying S-Term at one point, but I didn't get anywhere useful with my efforts.

all 4 comments
sorted by: hot top controversial new old
[–] CalcProgrammer1@lemmy.ml 14 points 3 months ago* (last edited 3 months ago) (1 children)

I'm not sure about FF specifically, but 99% of the time you're connecting a microcontroller to a PC you're doing so over a serial port (UART) of some sort. It may be a physical COM port or it may be a USB to serial adapter or even a purely virtual serial port over a USB connection, but the methodology is all the same. Unless you are running a serial terminal on that port (as in, a commandline on your PC served on the given /dev/ttyX interface, not a terminal emulator letting you read/write from the port), the microcontroller can't just run scripts on the PC. Instead, you will want to write a script/program that opens the port and waits for a command to be sent from the microcontroller, then that listener script can execute whatever functionality you require. Note that only one application can have the port active at a time, so if your listener is a separate program from your event handler, you will have to close the port on the listener before running the handler, then reopen the port on the listener once the handler is done so it can start listening for the next event. Better to just make it all one program that is always running on the PC and does both listening for events and handling them so there's only one program that needs access to the serial port.

[–] MarauderIIC@dormi.zone 5 points 3 months ago

Yup, pretty much this. I have a small touchscreen Arduino device that I keep plugged into my PC. When I hit a button on the touchscreen it sends some text over serial (which is really a USB wire). I have a Python script on the PC that continuously reads from the serial port and parses the received data to figure out what to do. Specifically it tells my Discord bot to play a sound :)

[–] bloodfart@lemmy.ml 6 points 3 months ago

From the uc side, open a serial connection, send data. On the host side, prepare a place for received data. On the host side, walk through the received data until the thing you’re looking for is found, then execute some action (in your case a python script).