Hello,
I am trying to readout a simple voltage between two AIN channels in python from a Labjack U6 Pro. It works well in CR mode, but stream mode gives me some issues.
My first problem is that the channel numbers i give streamconfig dont seem to match the numbers in CR. So for example, if I plug in a simple battery between AIN0 and AIN1 and read it out differentially, in CR it works like a charm, but in stream, I have to set something like:
d.streamConfig(NumChannels=2, ResolutionIndex=1, SamplesPerPacket=25, ChannelNumbers=[18,19], ChannelOptions=[7,7], ScanFrequency=100)
to get a reading of my batteries voltage. If, as should be, I set ChannelNumbers=[0,1], I just get some -10V reading.
My second problem is that, although ChannelOptions=[7,7], which according to the manual should be differential reading, I still get a dictionnary with 2 entries, one for each of the selected channels, instead of just the differential 1 dimensional readout.
How do I get my desired result ?
Thanks
Someone else will follow up about Python, but a quick note that connecting a floating battery to AIN0 & AIN1 is not a valid connection. See "Differential inputs must have a reference":
https://labjack.com/support/app-notes/differential-analog-inputs
Use this streamConfig instead for streaming differential AIN0-AIN1 with a scan frequency of 100 Hz:
d.streamConfig(NumChannels=1, ResolutionIndex=1, SamplesPerPacket=25, ChannelNumbers=[0], ChannelOptions=[128], ScanFrequency=100)
To point out the issues with your original call, the ChannelNumbers parameter specifies the positive channel of the reading, and ChannelOptions specifies differential (bit 7) and gain index (bits 4-5) settings. The negative channel of the differential is not specified in ChannelNumbers, and when the differential bit is set the negative channel will be 1 channel higher than the positive channel. Also, bit 7 (b10000000 = 128) in ChannelOptions specifies differential, not the decimal value 7 (b00000111).
Based on my testing once you set bit 7 to differential, then ChannelOptions bits 4 & 5 seem to be completely ignored.
I just wasted half a day trying to debug this. In single ended mode, bits 4 & 5 do indeed set the internal channel amplifier, but as soon as you set but 7, then it defaults back to the default gain and all the good resolution you wanted is lost.
This is particularly annoying as I need the differential input for a load cell and wanted to used the differential input with the onbaord amplifier.
Need help to solve ASAP!
I'm not sure what might be wrong with your code, but the different gains/ranges are supported in stream mode regardless of single-ended or differential. To see it in action, jumper AIN0 & AIN1 both to GND, and then to tell if the gain settings are working you can look at the noise level of your signal and compare to the expected noise levels:
https://labjack.com/support/datasheets/u6/operation/stream-mode
... or even more obvious, jumper AIN0 to VS and jumper AIN1 to GND. Now a single-ended or differential reading of AIN0 will read 5V using the +/-10V range, 1V using the +/-1V range, 0.1V using the +/-0.1V range, and 0.01V using the +/-0.01V range.
You can use LJStreamUD on Windows to quickly try this and confirm the operation of your device, and then if you are stuck with Python specific issues send a code snippet showing your stream configuration and describe what problem you are seeing.
Hello again,
I found a problem with the LJ readout, namely it oscillates by almost 20% randomly. I checked this by plugging a stable voltage source and writing down the readout in realtime. In case this is due to a mistake in programming, please let me know. Ive attached the corresponding script.
Thanks
It looks like you are converting samples twice. The first time with your streamData calls (which are using processStreamData), and the second with time with processStreamData. One potential issue is that your readings might be offset incorrectly depending on where the streamData stopped processing its data. For example, say the offset is at 1 at the end of streaming, when you call processStreamData, AIN0 data will be put into the AIN2 (offset 1), AIN2 in AIN4 (offset 2), and AIN4 in AIN0 (offset 0) . Try changing this call:
for r in d.streamData(convert=True):
To this:
for r in d.streamData(convert=False):
To help prevent this.
Alternatively you can keep "convert=True", create your processedDataList dictionary in your streamData loop with something like:
processedDataList["AIN0"].extend(r["AIN0"])
processedDataList["AIN2"].extend(r["AIN2"])
processedDataList["AIN4"].extend(r["AIN4"])
And not call processStreamData after your loop.
Let us know if that doesn't help. In that case, please let us know what frequency you are streaming at, and provide a set of samples with errors and what you were expecting. Also, please describe what is connected to your U6.
Thank you for the quick answer. However, I dont mean the final files that are being written after the loop, I am writing a rawdata file during the taking of the data called rawdata. That one only has the first conversion from convert=True. I am uploading a slightly updated version of the code where you can see what I mean.
I removed the previous conversions to strings, rounding up and reformatting since that could have been an issue as you mentioned, still the data I get from the LabJack is not as stable as the input it gets.
Still, the data I measure oscillates randomly, especially in the third differencial channel, meaning AIN4&AIN5 where i just measure random data.
I seems, if I short circuit the latter to measure 0V differential, the first two channels work just fine. The same applies if I use channels AIN6&AIN7 instead. I tried using a fourth channel and short circuiting that one to see if then the other three would work, but without success.
What else can I do to make this work ?
Regarding code, your stream loop will have the correct offset:
l],r['AIN6'][l]))
rawDataStr)
for l in range(ppc):
rawdata.write("%f %f %f\n"%(r['AIN0'][l],r['AIN2'][
So that is fine. Note that when you get to this code:
processedDataList = d.processStreamData(
That is where the potential offset issue will occur for processedDataList since "d.streamData(convert=True)" . A quick fix could be putting this right before it:
d.streamPacketOffset = 0
Though you have some commented code in the streamData loop that would populate processedDataList correctly.
We will follow up with some troubleshooting regarding hardware.
First lets determine if there is something wrong with the U6 or something wrong with your signal. As I understand you are doing a 3 channel stream (what scan rate?) with differential channels AIN0, AIN2, and AIN4. Remove all wires (except USB cable), and jumper AIN0 & AIN1 both to GND. The readings from AIN0 should be close to 0.0 volts with the expected noise level:
https://labjack.com/support/datasheets/u6/operation/stream-mode
So if you are using the defaults of Range=10 and ResolutionIndex=0=1, we expect about +/-3 counts of noise and each count is about 20/65536 = 300 uV.
Do the same test on AIN2/3 and AIN4/5. You can test one at a time or all at the same time or whatever. Should not make a difference.
So, I did that and I compared with what your windows software is reading out from the U6.
I still get very high noise, regardless of the packets per sample or resolution index set. The windows software on the other hand seems to read out stable values of the applied voltage on the same computer and USB port.
The readout happens with the exact code I uploaded before, and the channels in between are jump wired to show 0V in differential.
What else could it be ?
I discovered, that the noisy part of the measurement only occurs after about 1s of measurement, hope that helps for diagnosing the problem.
Just to confirm, you are using 6 small jumper wires to securely connect each AIN (0-5) to GND. You are using Range=10 and ResolutionIndex=1. With some Windows software you see noise on the order of +/-1 mV as expected. With your software you see much more noise. Is that what you are seeing?
What Windows software are you referring to? Same good noise level whether you look in Kipling or LJLogUD, or whether you use LJStreamUD and start streaming?
In your software try taking some single-ended readings and see if they are any different than the differential readings. Since all channels are shorted to GND you should get the same either way.
Hi, not exactly. I have a constant voltage on every second channel starting from AIN0-AIN1. Every second channel, starting from AIN2-AIN3 is shorted, but with no connection to GND. I believe I used LJLogUD, but I just had a quick look on windows to see what was going on.
I did single ended readings a while ago, Id have to check again and come back to you.
I couldent find how to set the range in streamConfig, how do I do that ?
I have a constant voltage on every second channel starting from AIN0-AIN1. Every second channel, starting from AIN2-AIN3 is shorted, but with no connection to GND.
I am not following what you are saying, but for this basic testing you want a short jumper from every channel to GND. So if you want to test AIN0 through AIN5 you need 6 short jumper wires.
To configure the range, use the ChannelOptions parameter. Bits 4-5 specify the GainIndex (range). There is table 5.2.12-2 here with the options a little more detailed than the Python doc:
https://labjack.com/support/datasheets/u6/low-level-function-reference/s...
For example, if you wanted differential and the range +/-1 V, that is GainIndex d1 (gain x10). It would look like this in ChannelOptions:
# Bit shifting the settings to their appropriate bit location. Decimal value = 144.
chanOpt = (1 << 7) + # Differential (bit 7)
(1 << 4) # GainIndex (bits 4-5)
d.streamConfig(NumChannels=NC, ResolutionIndex=1, SamplesPerPacket=spp, ChannelNumbers=[0,2,6], ChannelOptions=[chanOpt,chanOpt,chanOpt], ScanFrequency=freq)
Note that the gain settings will affect the maximum scan rate of the stream as shown in table 3.2.1 here:
https://labjack.com/support/datasheets/u6/operation/stream-mode
Alright, so I got the problem. I dont know if thats marked in the manual somewhere, but unless all other AIN channels are shorted and grounded, the data obtained by the LJ is just extremely noisy.
This holds regardless of the streamconfig options and the number of channels that are being monitored.
No, with valid signals, it does not matter what is connected or not connected to other channels. If you are seeing that the readings from your signals are affected by what is or is not connected to other channels, it suggests your signals are not properly driven or not properly connected. Grounding all other channels might make readings from your signals look better, but I would not count on that as a way to get good readings. Rather I suggest you investigate your signals if we find they are not properly driven.
Did you do the test I described? With AIN0 & AIN1 both jumpered to GND, you should find that any type of reading (differential AIN0 or single-ended AIN0 or AIN1) reads 0.0 volts with the expected good noise levels, regardless of what is connected or not connected to other channels. Can you confirm that, and then connect your signal, describe how its readings are different, and describe how it is connected.
Make sure your signals are not un-referenced:
https://labjack.com/support/app-notes/differential-analog-inputs
... or too high of impedance:
https://labjack.com/support/app-notes/SettlingTime
Grounded readings of all channels show 0.0V with very little noise. Now that the other channels are grounded though, once again, I get very bad data. Now the data jumps between the actual signal and 0V. It does not seem to follow a logical pattern.
I believe what you are saying is that if you ground some channels those channels read as expected, but channels with your signals connected do not read as expected. Just connect 1 of your signals (or 1 pair if applicable) and confirm this is what you see. Then tell us more about where these signals come from and what connections you have to the U6.
I removed all groundings from the other channels and measured only AIN0 with the attached code, with nothing plugged into the channels and then with a stable 5V source, the signal being unreferenced. Here are plots of the obtained data with the attached code, please disregard the plots titles:
https://picload.org/view/daaidaii/0v.png.html
https://picload.org/view/daaidaiw/5v.png.html
When I measure 3 channels in differential (code attached), where, AIN2 and AIN4 are left empty and AIN0 gets a stable 5, referenced 5V source, I get the following nonsensical results:
I absolutely need this data acquisition working until tomorrow morning, I hope we can find a solution until then.
Your plot of 0V seems good with readings around 0.
Your plot of 5V seems good with readings around 5.
In your last post you attached some code but I do not see a plot or any data.
To test AIN0 differential, connect AIN0 to VS or GND, and connect AIN1 to GND. It should read 5 volts or 0 volts as expected. The other channels with nothing connected have no meaning because they are floating:
https://labjack.com/support/app-notes/floatingunconnected-inputs
Here the picture that did not load, ie. 3 channels in differential (code attached), where, AIN2 and AIN4 are left empty and AIN0 gets a stable, referenced 5V source:
I dont think it makes too much sense trying some basic configurations like you suggest unless you can find the issue with that. To me, it seems like there is something wrong either with my data acquisition code, the LJ python library or with the exodriver.
Again this plot looks as expected. Your channel with something connected is reading 5 volts. The channels with no connections are floating, and thus the voltage on those channels is undefined, and the readings you get from them are meaningless.
Hello, I have attached a few figures of the output Ig get from the LJ U6 pro. Figure 1 represents a measurement of the first 3 channels, where between AIN1-AIN0 I have a stable 5V source, with a jumper to GND for reference. AIN2-AIN5 have a fluxgate, ie. a magnetic field probe attached and measuring in differential with the code I uploaded previously.
The single plots were taken consecutively measuring AIN1-AIN0 with the exact same setup, ie. the stable 5V source at the pins. The datapoints in the plots are 0.01 s apart, ie. single measurements every 0.01s are shown in the plot.
As you can see, the data is gibberish, even the 2 consecutive single runs are not at all reproducible. Please try my code with an LJ U6 Pro of your own and let me know if it is the code. The device itself seems to work fine as it measures sensible data under windows. So either something is wrong on the python side or on the exodriver side, but it has to work soon.
I ran your code on Linux which is using LabJackPython and Exodriver, and readings looked good with our test connections. For my test, all negative channels are grounded. DAC0 is set to 2.5 V and connected to AIN0, VS to AIN2, and GND to AIN4. Table results are attached and generated from your code (the title has incorrect information regard 3.4 and 2.6 voltages).
Try the same connections/signals and see if they compare to our results to confirm expected signal readings. Then we can try to troubleshoot with your system's signals.
Others things to consider, try and answer:
1. Make sure connections to the U6 screw terminals are secure (in the terminals and clamped down).
2. Try a different USB port and wire.
3. Try your Python code on Windows to compare results with.
4. What operating system are you using, version of Python, and version of LabJackPython. The latest is on GitHub (click on clone or download, and download):
https://github.com/labjack/LabJackPython
I am using opensuse 42.2, but I tried the same measurements on the latest version of Archlinux, same results, newest LJpython version, python itsself is set ti v2.7.
I shorted and grounded all channels except AIN1-AIN0, where I first set a stable 5V source, which gives good results (attached).
But as soon as I plug the magnetic probe into it, I get gibberish again, also at the other channels (attached). That remains true at gain x10 when the fluxgate is plugged in.
I believe I found my issue in the most common mistakes to be made for differential readouts. I was told the fluxgate I was using was floating and it would be a mistake to ground it like instructed in the LJ notes:
https://labjack.com/support/app-notes/differential-analog-inputs
That information seems to have been faulty as now I get sensible results which I verified with the oscilloscope.
If you have an isolated signal pair, you can connected single-ended:
Signal+ to AINx
Signal- to GND
If you don't want to refer the instrument to ground this way, you can do differential and then add a 100k resistor from Signal- to GND. This provides enough of a path for the bias currents, but maintains 100k of isolation between the signals and LabJack ground.
Signal+ to AIN0
Signal- to AIN1
100k resistor also from AIN1 to GND