Posts with «8-bit» label

Upline: a minimal serial protocol for 8-bit IoT

Upline is a minimal serial protocol that turns any microcontroller into an IoT device. The project sheet describes a system based on newline-delimited ASCII records, with a complete Arduino implementation in a single header. The project, by smlcrft, targets 8-bit chips with very limited resources.

The operation is simple. The byte stream is split into lines using LF or CR terminators, ignoring empty lines and those that do not start with the ‘^’ character. Each line is a list of independent entries, delimited by the same ‘^’ character. Each entry represents an operation on a specific key.

How the Upline protocol works

Entries are only processed if fully delimited by two carets. This way partial data is never applied, and an interrupted communication does not leave the device in an inconsistent state. Writes are confirmed via an echo of the value actually in use: this distinguishes a rejection from a loss of communication.

A periodic heartbeat demonstrates that the device is alive and speaks the Upline protocol. This limits the receiver’s wait time, which immediately knows if the node is operational. The protocol also supports escaping special characters with six symbolic sequences, and does not require floating-point numbers: it uses the fixN format for decimals.

  • 4,060 bytes of flash on ATmega328P, 358 bytes of SRAM
  • 3,168 bytes of flash on ATtiny85, 253 bytes of SRAM
  • 2,100 bytes of flash on ATtiny85 in transmit-only mode
  • 98 bytes for a universal line reader on ATmega328P

The numbers are remarkable for a complete protocol. On ATmega328P, 4,060 bytes of flash and 358 bytes of SRAM are needed. On ATtiny85, consumption drops to 3,168 bytes, and in transmit-only mode to 2,100 bytes. The project sheet also reports 98 bytes for a universal line reader on ATmega328P.

Why Upline matters to makers

Upline lets you turn any microcontroller into an IoT device with a minimal, efficient, and robust protocol. The philosophy is the opposite of heavy frameworks: here everything fits in one header and runs even on 8-bit chips with only a few hundred free bytes. An Arduino Nano ESP32 board can use the same protocol as an ATtiny85, simplifying communication between heterogeneous nodes.

The protocol is particularly suited to those building distributed sensors, remote actuators, or small monitoring nodes. Moreover, the echo confirmation makes the system reliable even over noisy radio links. To connect a node to a PC and read the record stream, just use a 3.3 V / 5 V USB-serial converter: Upline speaks over any UART.

Getting started with Upline

To start, simply download the upline-arduino header and include it in an Arduino project. The fact sheet lists support for ATmega328P, ATtiny85, SAMD21, ESP32, and RP2040, among others. An Uno R3 with an ATmega328 is a great test bench to learn the protocol without soldering anything: those are the 4,060 bytes of flash measured by the author.

The source code is a single header file, so integration is immediate. No external libraries or complex build tools are needed. A USB ATtiny85 board is instead the project’s edge case: 3,168 bytes of flash and 253 of SRAM, and the protocol fits entirely inside.

Finally, the project documentation reports precise numbers for each configuration. This helps choose the right microcontroller based on flash and SRAM budget. For the smallest projects, transmit-only mode on ATtiny85 requires just 112 bytes of SRAM.

Source: https://github.com/smlcrft/upline-serial-protocol

Related products

The post Upline: a minimal serial protocol for 8-bit IoT appeared first on Open Electronics.

8-bit volume control for Arduino tone()

Connor Nishijima has devised a neat trick to give the standard Arduino Tone() function 256 smooth volume levels using PWM at an ultrasonic frequency, without any extra components. This allows for programmatic control of square waves with nothing other than a speaker connected to an Arduino Uno.

Normally to simulate an analog voltage with a digital-only pin of a microcontroller you’d use Pulse Width Modulation. This works great for LEDs because your eyes can’t the 490 / 976Hz flicker of the standard analogWrite() function. But for audio things are a bit more difficult. Because your ears can easily detect frequencies between 20 – 20,000Hz, any PWM with a frequency in this range is out.

Luckily, the ATmega328P allows you to change the clock prescalers for ultrasonic PWM! We need to use Timer0, because it can drive PWM at a max frequency of 62,500Hz, which even if you cut that in half would still be above your hearing range. Now that we have ultrasonic PWM on Pins 5 & 6, we configure Timer1 to fire an Interrupt Service Routine at a rate of “desired frequency” * 2.

Finally, inside the Timer1 ISR routine, we incorporate our volume trick. Instead of digitalWrite()’ing the pin HIGH and LOW like the normal Tone() function does, we analogWrite() “HIGH” with our volume value (0 – 255) and analogWrite(0) for “LOW”. Because of how fast the PWM is running, the user doesn’t hear the 62.5KHz PWM frequency, and instead perceives a 50% percent duty cycle as a speaker driven with only 2.5 volts! While a few volume levels do produce subtle artifacts to the sound, it mostly delivers quality 8-bit volume control to replace the standard Tone() function.

When all is said and done, you’ll be able to customize your project with unique loudness as you play anything from the iconic Nintendo sound to R2-D2’s beeps and bops. In Nishijima’s case, he developed this Arduino volume-control scheme to make an incessant, inconsistent artificial cricket to hide in a friend’s vent for the next few months… You can read more on its Hackaday.io page, as well as find documentation and ready-to-use example sketches GitHub.

Arduino Blog 13 Jun 13:48