Customizing the MiniBee firmware

While the default firmware supports a lot of common sensors and actuators, in some cases you may want to customize the firmware to do something specific, e.g. when you have a sensor that is not covered by the default firmware, or when you want to perform some data parsing on the board. This page will show you how you can customize the firmware to your needs.

The starting point…

The default firmware looks like this (see the “MiniBee/standard” example):

// declaring the includes:
// creating an instance of the MiniBee:
MiniBee Bee = MiniBee();
// the setup function:
void setup() {
// the loop function:
void loop() {

Sending custom data

You can define pins that have a custom definition, by using setCustomPin in the setup() function:

Bee.setCustomPin( 10, 0 );
Bee.setCustomPin( 11, 2 );
Bee.setCustomPin( 12, 2 );

The first argument is the number of the pin (3 to 13 for the digital ones, 14 to 21 for the analog pins), the second argument indicates how many bytes of data the pin will provide. For an output pin (controlling something from the board) this will be 0, for an input pin this will be 1 or 2.

You then have to take care yourself to initialise the pins properly, by setting their pinModes.

pinMode( 10, OUTPUT );
pinMode( 11, INPUT );
pinMode( 12, INPUT );

In the loop() function you then have to add the data you created by calling the function addCustomData before the doLoopStep() function. The first argument of addCustomData is an array containing the data that needs to be added; the second argument is the size of this array:

int myData[2];
myData[0] = analogRead( 11 );
myData[1] = analogRead( 12 );
// add our customly measured data to the data package:
Bee.addCustomData( myData, 2 );
// do a loop step of the remaining firmware:

See the “MiniBee/customSending”-example for a full example.

Receiving custom data

You can also send wireless data to the MiniBee and perform a custom action with it. For this, you need to again define some custom pins (assuming you use some custom output for this), and define a callback function which is called whenever a custom message is sent to the MiniBee. For this you define a separate function (so not inside the setup() or loop() functions!):

void customMsgParser( char * msg ){
// this will be our parser for the custom messages we will send:
// msg[0] and msg[1] will be node ID and message ID
// the remainder are the actual contents of the message
// if you want to send several kinds of messages, you can e.g.
// switch based on msg[2] for message type
if ( msg[2] > 0 ){ // change speed yes/no
stepper.setSpeed( msg[3] ); // third argument of message is the speed
if ( msg[4] == 0 ) // third argument is the direction
stepper.step( -1 * msg[5] ); // fifth argument is the amount of steps to do
stepper.step( msg[5] ); // fifth argument is the amount of steps to do

In the setup() function you then add:

// set the custom message function
Bee.setCustomCall( &customMsgParser );

See the “MiniBee/customReceiving”-example for a full example.

The message you need to send to the MiniBees is formatted as follows:

  • ‘E’ – single character, indicating the custom mesage type
  • node ID – this is the identifier of the MiniBee we are targeting
  • message ID – this is an unique number for each message, in order to prevent the firmware from reacting twice to the same message
  • data – any number of bytes of data. These will be passed onto the callback function in the msg-bytes from index 2 and higher.

Additional functions

In case you want to define multiple customized pins at once you can do the following (in the setup() function):

uint8_t cpins [] = {4,7,8, };
uint8_t csizes [] = {0,0,0 };
Bee.setCustomPins( cpins, csizes, 3 );

You can also define inputs which are not connected to pins on the board with (in the setup() function):

Bee.setCustomInput( 16, 1 ); // 16 light inputs, 1 byte each

Fixed configuration

In some cases you may not want to have a flexible configuration, but instead fix the configuration in the firmware, for example if you are using the boards to communicate between each other, rather than with a central host. This can be done as follows…

Outside of any functions:

uint8_t myID = 3; // the nodeID of this MiniBee
char myConfig[] = { 0, 1, 0, 50, 1, // null, config id, msgInt high byte, msgInt low byte, samples per message
AnalogOut, Custom, AnalogOut, AnalogOut, Custom, Custom, // D3 to D8
AnalogOut, AnalogOut, AnalogOut, Custom, Custom, // D9,D10,D11,D12,D13
Custom, Custom, Custom, Custom, Custom, Custom, Custom, Custom // A0, A1, A2, A3, A4, A5, A6, A7

Inside the setup() function:

Bee.setRemoteConfig( false );
Bee.setID( myID );
Bee.readConfigMsg( myConfig );


Comments are closed.