Multiple Sensors, Multiplexing, and Serial Conn.

Hello all -

I’m currently working on a project where I may need more analog sensors (0-5V) than I can plug into the Arduino, so of course I’ve turned to multiplexing. The plan is to send these sensor values back to a computer running LabView, where they will be displayed in real-time (I should note that the serial connection will actually be two Xbee PROs, but I don’t think that affects my main question).

What would be the most efficient/practical way to send these multiplexed sensor values? And I’ve searched for this with no luck: how would I demultiplex the data in software on the computer end (not looking for specific code, I just mean how do you sort out what the multiplexer has done)?

If anyone has any ideas or could point me in the right direction it’d be a great help.

Thanks!

I made a setup with 16 slide potentiometers on 2 4051 mux IC's.

What i did was to read the value of all the 16 potentiometers, then send them to the PC as 16 comma seperated values followed by a carriage return / linefeed combination.

So on the PC side i allways now that i will recieve 16 values, then it's not difficult to telle which value belongs to which sensor. The CR / LF combo at the end makes it possible for my PC program to tell that it recieves all 16 values, and also in my case i can use a specific feature in the VB .net serial port class to read an entire line from the port buffer and split it into an array of 16 integers in a very easy and efficien way.

If you have to send the values seperatly, the i suggest that you allways send two values, first some kind of header that tells the PC program which sensor to associate the data with, and then the actual data. I don't know ifit is possible to use this setup with LabView though.

I hope this makes sense.

MikMo's comma separated suggestion is a good one, but as your post requested suggestions for the most efficient way, you may also want to consider sending your values as binary data. Here are some additional ideas using binary data for you to consider.

You will need a header to identify the start of a packet. Two bytes of 0xff is a good choice because this can never be a valid value from analog read. But you could get by with only sending on byte of 0xff if you send the data MSB first (because the MSB can't be 0xff)

If the number of values is likely to change in future you may also want to send a byte right after the header indicating how many values are to be expected.

Then send the values as byte pairs using something like the following:

int val

byte lsb = val & 0xFF; byte msb = val >> 8; Serial.print(msb, BYTE); // sends the MSB Serial.print(lsb, BYTE); // sends the LSB

The receiving side waits for a valid header then reads the data values, reconstructing the integer values from your sensors.

Thanks for the suggestions guys - unfortunately I haven’t been able to test anything yet, but I’ll try both of your ideas when I do.

(because the MSB can[ch8217]t be 0xff)

why is this? Im looking for a way for a computer program to display numerical values (straight from the binary) as well as text, sent as Ascii. This sounds like a good way in the absance of anything else!

1-Wire would be one way to go, just so long as reading, say, two sensors per second (i.e. 20 per ten seconds, etc) would be okay. All those sensors would take one Arduino pin. No, not one per sensor... ONE. (And quite a lot of software! No free lunches, sorry.)

More on 1-Wire, but NOT the Arduino part of the story at.....

http://www.arunet.co.uk/tkboyd/e1didx.htm

(See Arduino forumS for the Arduino part... it gets discussed in several places.)