Hobbyist Toolkit

Showing results for 
Search instead for 
Did you mean: 

How run BH1750 on Arduino Uno using LINX toolkit ?

Go to solution

Hi there,

I would like to run BH1750 sensor by LINX toolkit but I have not figured it out what should I use for Data of LINX Write, Bytes to read of LINX Read and index of index array. 

I have run it with Arduino itself and everything was fine but with Labview I had no luck. I have attached the block diagram.

Indeed, I appreciate your help


Download All
0 Kudos
Message 1 of 7
Accepted by topic author czxcz

Hey czxcz, could not open control in your VI, you just uploaded the VI.

by checking the pictures, you have so many coercion dots, and your logic does not correspont to data sheet that i built a new VI as Example for you.


Some things that i noticed, you must get 2 bytes of information to build your final measurements. I recommend reading the data sheet of your IC  thoroughly.


for my example i used an BH1721FVC, but it should work with your BH1750 with minor adjustments. for protocol, i checked both data sheets, and they are very similar.

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
0 Kudos
Message 2 of 7

Hi Jorge

Thanks very much for your help. Now it works!

I have another question regrading number of data measures per second: Measurement are approximately performed every 24 ms as it is obvious from first column of the attached file. Is it possible to reach down to 1 ms?

0 Kudos
Message 3 of 7

Can't say much as i dont know what your code does, you have provided only a screenshot of a fraction of your log file.


Anyway, you wont achieve 1khz daq with arduino and linx, top loop frequency is around 200hz

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
0 Kudos
Message 4 of 7

This is the diagram and measured data: At first a light source is blinked and then the changes are measured. Data time interval is less that 30 ms, almost 36 lux data per second but I am interested in a shorter time interval and more data per second. What would you suggest if I want to stick to Arduino Uno and be able to measure lux data with a time interval in order of 1 ms?


Download All
0 Kudos
Message 5 of 7

Why this fascination with always only attaching pictures instead of the actual VI (preferably backsaved at least one or two versions)?


As to you problem you need to consider this. Your program talks over serial port with the Arduino. Each message in a Linx packet takes at least a few bytes or more. The message needs to be transfered over the serial port, the Arduino (which is anything but a supercomputer cluster) needs to read that, parse the response into some data, call system functions according to those decoded data, interpret the response of those system functions and then format an acknowledge packet that is send back over the serial line and then received by the Linx VI to indicate if there was any error.


Each Linx VI has to wait until that final acknowledgement response has been sent back by the Arduino  and you have 4 of them in your loop. I'm sure you can see where things are going wrong.


But some of the things you do in that loop are mostly configuration things that do not need to be executed each time again, such as the I2C address configuration. You also only need to write the Digital channel when your Boolean switch actually changed its value.


There is no need to write a new value to the measurement in every loop, collect them together and write them every 100 or so samples at once. Writing one sample to disk costs exactly the same amount of time than to write 1000 samples, since the most expensive call is to actually open a file. If the write then transfers 8 or 8000 bytes, makes in comparison no difference.


With these optimizations you should probably be able to get the loop rate about halve the time or better. Also make sure to use the maximum baud rate that works reliable. 9600 baud definitely will limit your loop rate tremendously, since as we already said, there is several bytes with each Linx command that gets transferred back and forth and you have 4 of them. Let's assume 8 bytes per message in each direction, that makes already around 64 bytes per loop that need go over that serial port. That are about 640 bits so at 9600 baud your serial port communication would predominantly limit your loop rate to something like 15 Hz. Higher baud rates won't be the holy grail though. At some point the delay on the Arduino itself where it needs to decode, handle and then respond to each command will get more dominant and that you can't change by putting a different CPU on your Arduino.


To get 1kHz you would need to do the entire measurement cycle fully on the Arduino and then call this as a Linx custom command, but that is an entirely different kind of problem. It would require you to actually create your own Arduino INO program and link it with the Arduino Linx library. And that is a pretty advanced level programming exercise.

Rolf Kalbermatter
Averna BV
Message 6 of 7

well, czxcz, Rolfk has some points.


to be short (although Rolf pointed everything very clear), you wont be able to do 1KHz daq with BH1750 because it simply does not allow that.


The 150ms stall dataflow i put in the example is because this part of the datasheet:




Best case scenario, with everything optimized, you get a worse resolution, and 62 samples per second.


Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
0 Kudos
Message 7 of 7