0

I wanted to know if it is possible to run system commands on computer using raspberry pi pico when plugging it into the USB?

I've tried to do it like a normal C program :

#include "pico/stdlib.h"
#include <stdlib.h>
#include <stdio.h>

int main() {
    printf("Start");
    stdio_init_all();
    char *cmd = "ls";
    system(cmd);
    return 0;

}

Although printf works very well, system functions (eg: readfile) doesn't work.

Is there any way that i could run some kind of actions on PC using pico usb output ?

Also, there is a project called picoducky which allows the pico to run commands on system but unfortunately it has written in python and i'm looking for c code.

  • 1
    This isn't as simple as just outputting data over a serial, and there's no innate way to control a computer in that way. The ducky-type devices generally act as an input device like a keyboard. You should look at the HID examples for the Pico. – Thomas Jager Aug 26 '21 at 16:21
  • 1
    You cant execute system commands as it does not have OS and command line interpreter. – 0___________ Aug 26 '21 at 16:31

2 Answers2

3

Pico communicates with Pc using usb-to-serial and vice versa. Unless there is a server on Pc that interprets data send through serial than executes a cmd command, its not possible with the convetional way. However, you can make Pico emulate a USB HID device and send keystrokes. Check Tinyusb and this pico-superkey-board project

XenoiS
  • 116
  • 3
1

To be able to run system() function call in C in an embedded system, you need to know several things first:

  • system() calls the user shell with the string passed as argument as a parameter. Are you running an operating system at all? A shell is normally an operating system component, and it is not normally present in many embedded systems.
  • system() requires /bin/sh normally to work. To run ls, you need in adition to have it (the ls command) installed.

You don't say what operating system you have in your Raspberry pi pico, but I'm afraid it is not linux (or any unix flavour) so probably all of this is forbidden to you.

Normally, the requirements to have a unix like environment in a small system impede to use a high technology operating system in such systems. Linux requires large amoutns of memory (as there are in the normal raspberry pi, but not in the small versions), a large capacity storage system (bein a usb disk, flash memory card, etc. but normally several Gb for a minimum installation)

In your case, 264kb of ram are very small to have a non-mmu handled microprocessor, capable of addressing virtual memory spaces. Also 2Mb of flash gives you to write large programs, but not to install an operating system like linux.

Had you an emulator of system() you should be able to run other programs, but how? A raspberry pi pico has space to run just one program (the one you write to the flash and nothing else) Even if you write a kernel of a multitasking operating system, you would lack space to run filesystem stored programs, as you normally have limited access to the flash where programs are installed.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31
  • Thanks for the complete answer. In fact, I was trying to run that ```system()``` function on my PC through the USB output of pico. As others said i have to try some way to make an HID device instead of using system functions. – Polarspetroll Aug 28 '21 at 16:29