Library for ADS 1231 (bee hive weigh scale)

I have a running sketch with an Arduino and an ads 1231 ( to get values from a weigh scale.

I want to replace the Arduino with my Photon or Electron together with the Shield Shield.

I try to use/port the following library for the ads 1231:;topic=131086.0;attach=67564

but I got several errors:

'digitalPinToBitMask' was not declared in this scope
'digitalPinToPort' was not declared in this scope
'SREG' was not declared in this scope
'cli' was not declared in this scope
'portInputRegister' was not declared in this scope
'portOutputRegister' was not declared in this scope

#include "application.h" is included in the header-file.

I hope someone has some tips for me. Thanks in advance for your help!

@jensfranke, the arduino does “fast” GPIO using those functions listed. They are very arduino specific. The Photon has several “fast” GPIO functions which can be used instead.

From what I can see, the library controls the ADS1231 using 3 pins - scl, data and powerdown. With the Photon, you can set and reset the pins directly using pinSetFast() and pinResetFast() without all the fancy registers needed on the Arduino. So this block of code, for example;

		ADS1231s[this->ADS1231Index].sclBit =   digitalPinToBitMask(sclPin);  
		ADS1231s[this->ADS1231Index].sclPort =  digitalPinToPort(   sclPin);  
		ADS1231s[this->ADS1231Index].dataBit =  digitalPinToBitMask(dataPin);  
		ADS1231s[this->ADS1231Index].dataPort = digitalPinToPort(   dataPin);  
		ADS1231s[this->ADS1231Index].pwdnBit =  digitalPinToBitMask(pwdnPin);
		ADS1231s[this->ADS1231Index].pwdnPort = digitalPinToPort(   pwdnPin);


		ADS1231s[this->ADS1231Index].sclPin = sclPin;  
		ADS1231s[this->ADS1231Index].dataPin = dataPin;  
		ADS1231s[this->ADS1231Index].pwdnPin = pwdnPin;

The functions which use the pins, like sclPulse() for example, becomes:

    void ADS1231::sclPulse(){
        pinSetFast(ADS1231s[this->ADS1231Index].sclPin);    // set sclPin high        
//		delayMicroseconds(1);
       pinResetFast(ADS1231s[this->ADS1231Index].sclPin);   // set sclPin low        

If you feel bold, take a shot at the rest of the modifications. If you don’t feel ready, I can port it for you. :wink:


@peekay123 Great! Thanks for explanation and the code. I’ll try my best tonight. :smile:

1 Like

@peekay123 Finally I found the time to start porting the library:

The values from the weigh scale looks fine, but it would be nice if you can verify my particle library, especially the lines with the check-function.

Arduino Library:

Particle Library:

Next step is to test the power off function for power-down the ADS and write a function for a standby mode to reduce the power consumption.

Thanks in advance for your help & hints for refactoring the library.

@jensfranke, code looks fine! You may want to test on the arduino first assuming that library is proven good. Then test on your Particle device. :wink:

Hi, I’m a total noob writing code and no experience with C++ but I want to use 2-4 ADS1231 devices with the electron and your library is the only one I can find. Using your library, could you point me in the direction how i could sample multiple ADS1231’s? Perhaps @peekay123 could you help me?

@wineisgud4u, looking over @jensfranke’s library, I can see it hasn’t been worked on for three years! From the looks of it, it is not quite ready for prime time. You also need to know that you will need 3 GPIO pins per ADS1231 device (pins can’t be common). That makes for up to 12 pins in your scenario. I can whip up a quick Web IDE app and share it so you can test it.

UPDATE: I have no idea if this will work or not so YMMV. I test compiled for a Electron against DeviceOS 1.2.0-rc.2 without errors.

1 Like

Wow! That’s great. Thank you so much for laying out the structure. As a beginner, just seeing how you wrote you code helps me understand how things work. I do need to confirm how many unused GPIO’s I have available. 4 ADS1231’s might be too many. I could go with another chip - maybe a 4 channel 24-bit ADC with an I2C interface to save pins. Seems like there’s a bunch to choose from. If that proves to be a better option (because i just don’t have enough GPIO’s) which one would you suggest based on performance and on the availability of a solid, well vetted library for the Electron?

@wineisgud4u, using an SPI or I2C multi-channel device is definitely a better way to go. This library is “bit-banged” and will be slow. As for performance, that all depends on how fast you want to sample and how you process the data on the Electron. Using SPI is generally faster.

As for a “solid, well vetted” library, that will depend on the device you chose and if someone has contributed a Particle library for it. If not, a good Arduino library could also be ported.

Searching the Particle library the HX711 has been used by far the most. But it seems to work in a similar way as the ADS1231, but it only needs 2 GPIO’s per device, not 3. Not sure that really helps that much. I still think an 8 channel ADC (4 differential channels) would be better. I do see the ADS1220 (2 differential channels) has a library, so it’s an option. 10-80 SPS is fine for me. I’m only using it for weigh scales or thermistors, so I don’t need high speed. But, i do prefer to use ratiometric measurements. I find that to be more stable. I’ll keep looking around.


What load cells are you using?
You can have multiple HX711s use a common CLK pin so you’d only need n+1 pins for n scales.

I use custom load cells with a 350 ohm full bridge strain gauge. I’ve used various excitation voltages from 2.5-5.0V and 24-bit Delta Sigma ADC, which is why i tend to stick with ratiometric measurements. I also use thermistors. Maybe the H711 could be used with those as well?