Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A Communication with microcontroller via usart - using strings a good idea?

Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a go...

posted 1mo ago by Nick Alexeev‭  ·  edited 1mo ago by Nick Alexeev‭

Answer
#2: Post edited by user avatar Nick Alexeev‭ · 2026-08-05T20:08:48Z (about 1 month ago)
  • Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a good choice. Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).
  • The data frames either have start and stop markers. or a start marker and length field. There’s always a CRC or checksum field to detect possible data corruption.
  • > Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.
  • It’s better to send the command and the number of the relay in the same packet. You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.
  • You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code. That’s alright. If someday you need to switch to opcodes, that can be made readable in the code too.
  • ```C
  • typedef enum {
  • OPCODE_STATUS = 0x00,
  • OPCODE_RELAY = 0x01,
  • // more opcodes...
  • } Opcodes;
  • ```
  • ```C
  • switch (receivedOpcode) {
  • case OPCODE_RELAY:
  • // do your things
  • break;
  • // more opcode cases ...
  • }
  • ```
  • Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a good choice. Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).
  • The data frames either have start and stop markers. or a start marker and length field. There’s always a CRC or checksum field to detect possible data corruption.
  • > Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.
  • It’s better to send the command and the number of the relay in the same packet. You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.
  • You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code. That’s alright. If someday you need to switch to opcodes, that can be made readable in the code too.
  • ```C
  • typedef enum {
  • OPCODE_STATUS = 0x00, // Named constants make the numeric opcodes more readable in the source
  • OPCODE_RELAY = 0x01,
  • // more opcodes...
  • } Opcodes;
  • ```
  • ```C
  • switch (receivedOpcode) {
  • case OPCODE_RELAY:
  • // do your things
  • break;
  • // more opcode cases ...
  • }
  • ```
#1: Initial revision by user avatar Nick Alexeev‭ · 2026-08-05T20:05:53Z (about 1 month ago)
Command protocols which use strings are a norm.  They use more bytes compared to binary protocols, but they are human readable.  If the UART itself isn’t a bottleneck, then command strings are a good choice.  Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).

The data frames either have start and stop markers. or a start marker and length field.  There’s always a CRC or checksum field to detect possible data corruption.

> Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.

It’s better to send the command and the number of the relay in the same packet.  You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.

You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code.  That’s alright.  If someday you need to switch to opcodes, that can be made readable in the code too.

```C
typedef enum {
    OPCODE_STATUS = 0x00,
    OPCODE_RELAY  = 0x01,
    // more opcodes...
} Opcodes;
```

```C
switch (receivedOpcode) {
        case OPCODE_RELAY:
            // do your things
            break;
        
        // more opcode cases ...
}
```