querying sensors and sending all read data with a Nano?

Hi,

I need to read a few sensors:

DS18B20
DHT22 temperature-humidity sensor
Adafruit TSL2591 High Dynamic Range Digital Light Sensor
MiniPH I2C Interface MinipH I2C pH Interface - Sparky's Widgets

But my Arduino Nano is already reaching max. sketchsize with just loading the lib for the DHT22.
If I understand it right, I don't need to use the libraries if I just want single functions, like a data-read?

I having a hard time how to query all sensors like every 2-3secs and store the data in RAM until all is send over the UART to a RasperryPi3. This raises another question: what should I use to transmit the data over 30-50m of telephone-cable or Cat5-STP? Does plain UART work good enough or is there any lightweight protocol with a bit of errorcorrection?

Kind regards :slight_smile:

Hi,
Please post your code, using code tags?

http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks.. Tom... :slight_smile:

These days a pair of wireless modules is cheaper than 30m of cable.

But you still end up with cable to provide power. So it does make sense to use the cable for communications. If this is all within the same building, then you may probably get the serial pins on the Arduino to drive that length adequately. If not, then a couple of MAX232 RS232 converters on each end will boost the voltage up to push the signal through and overpower interference.

If this cable goes between two buildings, you have to consider lightning protection. A nearby strike can put a big voltage on the line and a burning Arduino is a good way of starting a house fire.

RS485 and other line drivers aren't necessary for this distance but that works very well with twisted-pair, so that's sometimes a good choice since Ethernet cable and phone cable is always twisted-pair.

You don't say what is max'ed out? FLASH or RAM? You may want to ask for ideas about reducing code size in the programming section.

Yes, you can use I2C without the libraries. You may need to configure and initialize your sensors.

I find that as I am writing code I put a lot of serial.Println() statements in to help debugging and verifying as I go, then I leave them in there. By the time I am done they are all over the place and taking up a lot of memory, especially when they contain longer "human readable" strings of text. I prefer to keep them, but comment them out. That way they don't get compiled and take up FLASH memory.

Lots of linear code takes up memory. If you are doing the same or similar calculations or manipulations in multiple places, commonize them into a function call.

Lots of global variables use up RAM pretty fast. Can you do more with local temporary variable? Can you reduce the number of intermediate steps saved in unique variables? Do you have different variables to temporarily hold raw values which are immediately converted into something more useful? do they need to be unique?