As an Amazon Associate we earn from qualifying purchases.
The STM8S is a family of low-cost 8-bit microcontrollers from STMicroelectronics. Small boards based on chips such as the STM8S003F3 are cheap and easy to find, which makes them a good choice for simple projects like LED control, sensor reading and keypad input.
The examples on this page are based on Sduino, an Arduino-style core for STM8S chips. If you already know the Arduino IDE, you can write familiar sketches with setup() and loop() and run them on an STM8S. You need to install Sduino before you can follow these examples.
What is Sduino?
Sduino is an open-source board package that adds STM8S support to the Arduino IDE. It lets you use functions such as pinMode(), digitalWrite(), digitalRead(), analogRead() and delay() on STM8S devices. Behind the scenes it uses the SDCC compiler to build the code for the STM8 architecture.
The main benefit is a shorter learning curve. You skip the vendor toolchain and work in an environment you may already know. The trade-off is that the STM8S003 parts have limited flash and RAM, so large sketches and heavy libraries will not always fit.
STM8S examples in this series
These are the project guides that go with this page. Each one explains the wiring and the code for a specific part or board:
The blinking guide is the best place to start. It confirms that your tools, board and programmer all work. The TTP229BSF guide is a step up: it reads a capacitive touch keypad controller with an STM8S003F3, so it uses digital inputs and basic timing.
Getting set up
1. Install the Sduino board package
Sduino is added to the Arduino IDE through the Boards Manager. Open the project’s GitHub page, copy the package index URL it lists, and paste it into the “Additional Boards Manager URLs” field in the IDE preferences. Then open the Boards Manager, search for Sduino and install it.
Follow the project’s own instructions for your operating system, because the required tools can differ between Windows, Linux and macOS.
2. Choose the right board and chip
After installation, pick the board entry that matches your hardware under the Tools menu. A generic STM8S003F3 breakout and a 32-pin STM8S003K3 board are different chips with different pin counts, so choosing the wrong one is a common cause of sketches that compile but do nothing.
3. Connect a programmer
The usual way to load code onto an STM8S is an ST-Link V2 programmer (or a compatible clone) using the single-wire SWIM interface. In general you connect four lines between the programmer and the board:
- SWIM (data)
- NRST (reset)
- GND
- Power (check whether your board expects 3.3 V or 5 V from the programmer)
Check your board’s documentation for the exact pin positions. Wiring mistakes here are a frequent reason for upload errors.
A simple first example: blinking an LED
A blink sketch is the standard first test. The logic is the same as on any Arduino:
- In setup(), set the LED pin as an output with pinMode().
- In loop(), set the pin high with digitalWrite().
- Wait with delay(), for example 500 milliseconds.
- Set the pin low and wait again.
The pin number depends on your board. Many small STM8S boards have an LED on a specific port pin, but not all do, so check the schematic or add an external LED with a resistor. The full wiring and code are in the STM8S003K3 blinking guide linked above.
Tips for working with STM8S and Sduino
- Keep sketches small. The STM8S003 chips have limited memory, so avoid large libraries and big text strings.
- Check pin naming. Sduino maps Arduino-style pin numbers to the chip’s port pins. Look at the pin mapping for your board before wiring.
- Mind the voltage. Make sure sensors and modules run at a logic level your board supports before connecting them.
- Test one thing at a time. Get blinking working first, then add inputs, sensors or displays.
- Use a common ground. When you connect modules, such as a keypad controller, share ground with the STM8S board.
Troubleshooting common problems
The sketch will not upload
Check that the programmer is detected by your computer, that the SWIM and reset wires are connected correctly, and that the selected board matches your chip. Try a different USB port or cable if the programmer is not recognised.
The sketch uploads but nothing happens
Confirm the pin number in your sketch matches the pin you wired. Also check that the LED polarity is correct and that you used a current-limiting resistor.
Compile errors about memory
This usually means the sketch is too large for the chip. Remove unused code or libraries, or move to an STM8S device with more flash.
Where to go next
Once the basics work, try reading a switch, driving a small display or connecting a sensor. If you also want to compare other platforms, our MSP430G2 LaunchPad examples cover another low-cost microcontroller board. For general circuit simulation practice, see our Proteus examples, and for another beginner-friendly control topic, there are the PIC16F877 ladder logic examples.
FAQ
Can I program an STM8S with the Arduino IDE?
Yes. By installing the Sduino board package, you can write Arduino-style sketches and build them for supported STM8S chips from the Arduino IDE.
Which programmer do I need?
Most people use an ST-Link V2 or a compatible clone connected through the SWIM interface. Check that your board exposes the SWIM and reset pins.
Is the STM8S003F3 good for beginners?
It is a reasonable low-cost starting point for simple projects, but its memory is limited. If you plan to use large libraries or complex code, a chip with more memory may suit you better.
Do Arduino libraries work on STM8S?
Only some do. Libraries that depend on specific AVR hardware usually will not work, and big libraries may not fit in memory. Libraries written for Sduino or with simple, portable code are more likely to work.