Hive scale code

Hi Folks, looks like I’m first to post to this group so I’ll try and get the ball rolling. I’ve successfully had hive scales running for quite a few months now, using first Moja and then Mbili. I’m going to run a makers workshop in Melbourne to get a group to build their own. Because the Mbili is now being phased out I plan to use the Autonomo. Does anyone know any issues about porting the code across?
Cheers, Andrew

I’m just about to set up a hive scale with an Autonomo. Just caught a swarm yesterday and moving it to what will be a sensor heavy hive (hope to eventually add some Open CV to count arrivals and departures). What does your code look like and which scale did you use?


I use 4 load cells from Dongguan South China Sea Electronic Co Ltd with a Sparkfun Hx711 amplifier. Code is my own (very amateur) adaptation based on the interrupt example provided by Gabriel Notman (he called it structured sleep).

I’m currently struggling getting the Autonomo working with the GPRSbee.

I have experience with porting from Seeeduino Stalker 2.3 to Autonomo only.
All my experience are based on HX711 + xBee Series1 + Dallas temp sensor. The primary issues were:

  1. Sleep/awake operations
  2. RTC setup

The Autonomo does far more in one package than the Mbili: on the Mbili, the USB chip, RTC and 1284p microcontroller are separate packages while on the Autonomo, they are in one package. Also the architecture of the microcontrollers is different: The old one is AVR based, while the Autonomo is based on an ARM architecture. In practice, this means that any code that wrote something to microcontroller-specific registers (like the RTC or USB) will have to change.

From an electrical perspective, an Mbili GPIO pin can drive 40 mA while an Autonomo GPIO (much more a low-power design!) can drive only 7 mA. If your Mbili system had pins that used more than 7 mA, the system needs to change otherwise the Autonomo can be damaged.

OK, sorted the Autonomo-GPRSbee thanks to Gabriel Notman’s excellent advice. Now for the interrupt routine.

Gabriel hope you can help. I’ve used the example of the RTC_WakeISR from your GitHub. It seems to go to sleep fine, but not wake up. I can get the simpleRTCAlarm to work, so it just seems as though the alarm isn’t triggering the exit from sleep. Hope its something simple.
cheers Andrew

OK I’ve answered my own question - its already been dealt with in a previous posting! This is to do with having the Serial port open - see forum post: AUTONOMO: SerialUSB use freezes after resuming from deep sleep. The routine works once I turn off my debugging print commands. I’ll have a play with the USB attach and detach commands.

I’ve sorted out the code and Autonomo is working well with my hive scale. I couldn’t get the USB attach/detach commands to stop the system crash when using the serialUSB as well as sleep. So I set up a #define DEBUG and then use #ifdef DEBUG to either run print commands or sleep. But I agree with BelgoTrack, it would be good to be able to use sleep and the serial for debugging. Gabriel, do you think you could have another look at this? Cheers…

One thing to bear in mind is that the when the Autonomo enters sleep mode it shuts down the USB peripheral on the MCU. This will close the session in most, if not all, terminal programs (PuTTY, Arduino Serial Monitor etc). After the Autonomo exits from sleep, a new session will have to be opened with the device (closing and re-opening the Serial Monitor will do this).

It is also possible to detect if the USB cable is attached and only enter sleep if it isn’t. Additionally, there are commands to detect if the cable was reconnected while in sleep mode. This effectively will wait, after waking, until the connection with the host is re-established.

The detach command disconnects the device from the host. If this is not used the host will think the device is still connected and will likely give some error do to a lack of response. (I often see messages stating device is not recognised).

Interesting Gabriel, can you share with us how that is done ?

There is a bit in the USB->DEVICE.CTRLB register called UPRSM which when asserted will attempt to re-establish the USB connection. If no cable is present, it will time out after about 5ms (based on measurements). That same bit stays asserted until the operation has completed or has timed out. You need to wait until that bit is cleared.

Also have a look at the USB->DEVICE.FSMSTATUS register for the current state of the USB device. It should be in the suspend state when the cable is unplugged.

1 Like

I have developed a hive monitoring system, “Open Hive”, based on an Seeeduino Stalker with a custom shield (for an ADS1231 as load cell ADC alternative to the HX711), and the Sodaq GPRSBee for data transmission. You can find some pictures under

code see

We have also developed a huge backend and middleware to transport data from a node via radio (RFM69, Lora is with the RFM95 starting), see the Hiveeyes website:

There is now a Scale Adjustment sketch for the ADS1231

and also for the HX711