Archive for the ‘Arduino’ Category.

Finite State Machine Generator for C

For quite a long time I’m thinking about simple code generating tools. I don’t want to use a special XML syntax or descriptive language but a simple Excel or OpenOffice sheet instead.

The aim is to generated C source code for small microcontroller applications or retrocomputing systems.

For the start I made a simple generator for finite state machines (Wikipedia entry)

It is also my first script written in Python and thus not really as tidy and neat as I prefer. But it is working for now.

It takes the sheet from an OpenOffice .ods table like this:

@brief autofire button statemachine
@see    
     
State Event Next State
INIT KeyPressed PULSE_ON
INIT KeyNotPressed AUTOFIRE_OFF
AUTOFIRE_OFF KeyPressed PULSE_ON
PULSE_ON KeyNotPressed AUTOFIRE_OFF
PULSE_ON PulseTimeElapsed PULSE_OFF
PULSE_OFF KeyNotPressed AUTOFIRE_OFF
PULSE_OFF PulseTimeElapsed PULSE_ON

and generates a switch-case style state machine in C with callback functions for state and event handling.

A version with support for object oriented programming with pointers to statemachine objects is planned aswell. Check the github for functional updates.

The actual code can be found on Github: https://github.com/simonsunnyboy/gen-fsm

Arduino Sketch zum Auslesen des EEPROM Inhaltes

Um mein mySmartUSB light Programmiergerät zu verifizieren, habe ich folgenden Arduino Sketch ausprobiert. Der Arduino zeigt damit seinen EEPROM Inhalt in HEX Notation in der seriellen Konsole an.

/* Display EEPROM contents from Arduino UNO
 * (c) 2014 by Matthias Arndt
 */
#include <EEPROM.h>

void setup()
{
  uint16_t addr = 0;
  uint8_t c;
  uint8_t nl = 0;

  Serial.begin(9600);
  Serial.print("Arduino EEPROM contents:\n\n");

  while(addr < 1024)
  {
    c = (EEPROM.read(addr) & 0xFF);

    addr++;

    Serial.print(c, HEX);
    Serial.print(' ');

    if(nl < 31)
    {
      nl++;
    }
    else
    {
      Serial.print('\n');
      nl = 0;
    }

  }

}

void loop()
{
  for(;;);
}