I have a running sketch with an Arduino and an ads 1231 (http://www.ti.com/lit/ds/symlink/ads1231.pdf) 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:
http://forum.arduino.cc/index.php?action=dlattach;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!

@jensfrankethe 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 seethe library controls the ADS1231 using 3 pins - scldata and powerdown. With the Photonyou can set and reset the pins directly using pinSetFast() and pinResetFast() without all the fancy registers needed on the Arduino. So this block of codefor 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);

becomes:

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

The functions which use the pinslike sclPulse() for examplebecomes:

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

If you feel boldtake a shot at the rest of the modifications. If you don’t feel readyI can port it for you. :wink:

2 Likes

@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: https://github.com/jensfranke/ads-1231-particle-library

The values from the weigh scale looks finebut it would be nice if you can verify my particle libraryespecially the lines with the check-function.

Arduino Library: https://github.com/jensfranke/ads-1231-particle-library/blob/master/arduino-src/ADS1231.cpp#L64-L70

Particle Library: https://github.com/jensfranke/ads-1231-particle-library/blob/master/particle/ADS1231.cpp#L65

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.

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

HiI’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 librarycould you point me in the direction how i could sample multiple ADS1231’s? Perhaps @peekay123 could you help me?
Thanks!

@wineisgud4ulooking over @jensfranke’s libraryI can see it hasn’t been worked on for three years! From the looks of itit 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.

https://go.particle.io/shared_apps/5cf13d8cb3ec5e000b5e85cf

1 Like

Wow! That’s great. Thank you so much for laying out the structure. As a beginnerjust 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 solidwell vetted library for the Electron?

@wineisgud4uusing 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 performancethat 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 “solidwell vetted” librarythat will depend on the device you chose and if someone has contributed a Particle library for it. If nota 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 ADS1231but it only needs 2 GPIO’s per devicenot 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 libraryso it’s an option. 10-80 SPS is fine for me. I’m only using it for weigh scales or thermistorsso I don’t need high speed. Buti do prefer to use ratiometric measurements. I find that to be more stable. I’ll keep looking around.

2 Likes

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 ADCwhich is why i tend to stick with ratiometric measurements. I also use thermistors. Maybe the H711 could be used with those as well?