Embedded Electronics Tutorials, Coding and lot more

How to setup a service to execute automatically when beaglebone boots?

Suppose you are developing an application on beaglebone black, and after the debugging process is finished, now if you want it as a stand alone product then it is not possible directly. Because every time to run your program (in whatever language: C, C++, Python), you were triggering it to run the program by logging in via ‘ssh’ or direct GUI. But this way is not feasible for the actual product. The actual device should start operating itself as per required application, when it boots. We cannot use Laptop/PC that time. So here there is a way by which you can enable your Beaglebone to run your actual program when it boots. So it directly starts your application.

For example, you are creating a barcode reader device, then your beaglebone should be able to start accepting and processing data from barcode device directly right from the boot time.

So this process is called assigning system startup services to beaglebone.

Lets make a service which sends some string to serial port when beaglebone boots. We will send “I am rebooted now” via UART1.

UART1 :- Rx : P9_26   Tx: P9_24    RTS: P9_19    CTS: P9_20  Device: /dev/tty01

Note: USB to ttl converter is required. Take care, you must not connect its 5V pin on any GPIO pins of Beaglebone. Any type of devices such as PL2303, FTDI, CP2102 you can use.


Now lets make a python script to perform our task first. Make a program to send some string on serial port via UART1. Here’s the code shown below.  Use vi editor for that.

In terminal type: vi uart.py


After typing in correctly press Esc key.

The quit by pressing :wq

Now if everything was correct, go to command line and run script as

python uart1.py

To check output , we will use Minicom serial terminal to see the incoming data. So lets go back to your Linux host and first setup minicom.

On host PC Type: sudo minicom -s

you should see this screen:

beaglebone uart

Select Serial port setup. and change settings as following screen by navigation keys.


Then save this settings as default and then exit. You should see the serial terminal window. Now lets test our code.

Now, again run our python file then you should see the output as “I am rebooted now” in the minicom.

Now we will make a service for this task. The steps are as following.

Use vi or nano editor and create a new file in /lib/systemd/system/ (stest.service in my example) with a content like:

Screenshot from 2015-01-03 16:29:59

Then execute the following command to install the service:

systemctl enable stest.service

To start the service, you can reboot or execute

systemctl start stest.service

To check if the service is running and get the latest outputs from the script:

systemctl status stest.service

Now reboot your device and it should send the string via serial port at the boot time within 10 seconds approx.

Sharing is caring

1 Comment

  1. I got what you mean ,saved to favorites, very nice internet site.

Leave a Reply

Your email address will not be published.



Theme by Anders NorenUp ↑

Follow Me

Get the latest posts right delivered in you mailbox

%d bloggers like this: