LED control for taking photos

Hello, first of all thank you for providing this amazing tool. I am currently working with the microscope to monitor the change in morphology of a cancer cell. For this I have to keep the microscope inside the incubator for a whole day taking pictures every 10 minutes, for that I am using the blockly extension. However, different problems have arisen, one of them is that the LED that illuminates the sample over time causes the culture medium to evaporate. I would like to know if anyone has any idea how to make the LED turn on and off at 10 minute intervals so that it only turns on when it has to take a picture. Thanks in advance.

@Soyalexf switched LED control is not standard in the microscope, so this will I think require some additional building, depending on your system. Which version of the microscope are you using? The photographs look like a standard microscope, have you put a Pi camera on that microscope to use the Openflexure software? or is it an Openflexure microscope that you have in the incubator? Are you using Openflexure motor control?

The Blockly extension is simple to use and is particularly useful for your kind of time sequence, I have used if for exactly that for inorganic objects. However it does not give you all of the possibilities of the different parts of your system. To get the LED to go on and off, fully integrated with your image capture control, you would I think need to use the Python client locally on your microscope Raspberry Pi. Then you should be able to control the GPIO pins of your Pi as well as talking to the microscope server for the pictures and focussing.

As your image capture is infrequent, a less elegant method would be to use a completely separate system to switch the LED on for 20 (or 10) seconds every 10 minutes, and set that running about 10 (or 5) seconds before setting your Blockly program running. It is unlikely that the microscope and the LED would get out of synchronisation in a day. You could do the LED On/Off using an Arduino, which would be very simple for a low current LED. If you need more than 20mA through the LED that would require some extra parts.

1 Like

The photos are just to show how the culture evaporated in one sample. I am using the V6 microscope, not the Delta. I found a relatively easy solution. On an ESP32 that I had to spare, I made a small code so that there would be a cycle of 9 and a half minutes with the LED off and 30 seconds with it on. By the way, thank you very much for taking the time to reply. I would like to show you a photo of the microscope inside the incubator for you to see, but I am not in the laboratory today. I’ll upload it in a few days. Thanks again


Great that you found a solution. That is the simplest way to do it, but does mean that the LED is on for quite a lot longer than is strictly necessary. It would be nice to have a function in the software to activate a pin on the Pi or on the motor controller that you can use to synchronise external functions like this.

1 Like

It would be super to add some sort of easy GPIO into both the web API and the blockly client - I suspect the latter will take a while to materialise, but perhaps the former is not so difficult with a microscope extension. I know @filip.ayazi has used the Raspberry Pi GPIOs, and there’s some promising stuff on the new sangaboard - but I suspect neither of those would do what’s needed right now.

Once the GPIO function is exposed as a web request I think I can remember how to add it as a block in Blockly.

As Richard said the new Sangaboard can control the LED (though I don’t know much about the blockly integration so that might come a bit later). An extension to control a raspberry pi GPIO wouldn’t be difficult to write, but I’m not sure the GPIO can directly provide enough current, I think it can only do 16mA. If that is enough current (or there is a transistor or relay involved) the ESP32 workaround can be replaced by a bash script on the Pi using one of the gpio control commands on the pi, for example with raspi-gpio on gpio 20

raspi-gpio set 20 op #set output
while true
raspi-gpio set 20 dh #led on
sleep 30
raspi-gpio set 20 dl #led off
sleep 570
1 Like

The Blockly part is quite simple, it just needs there to be somewhere to send the request to. We probably would also need to define a single pin (or two pins) that this is enabled on, and decide whether it is on the Pi or the motor controller.

Yes, you are right. It would be very convenient to use the GPIOs of the Raspberry Pi, but the flexibility that the ESP32 (or the Arduino Nano that I plan to use as a substitute) gives you many options. For example, I adapted a button to start the cycle. I suppose it can also be done through the pins of the Raspberry Pi, but in my case, I don’t know how. Of course, the best option would be integration with Blockly

1 Like

Hi, a small problem has arisen, apparently over time the cycle becomes unsynchronized, I think it’s because the photo takes more than 1 second, I tried to time it and I think on average it takes 3 seconds, can you confirm this for me? This problem makes it clear to me that the definitive solution is to be able to control the LED using Blockly, I hope this can be done soon. Thank you.

Taking about 3 seconds to take a photo sounds reasonable. Your measurement will be closer to your reality than anything from a different system. 24 hours with 6 pictures per hour is ~150 pictures, so I suppose that means you need to get the average time to take an image correct to well within a second in order to have the LED on for less than 60s for each time and remain sufficiently synchronised.

Getting an extension that gives control of auxiliary outputs on the API, that we can then add to Blockly, is tied into a number of other improvements to the software that all need to be done together. It is planned to happen, but will not be immediate. Either the Python or Matlab clients will allow you to talk to the microscope and also talk to other peripherals. They are not as easy to get started with, but should be able to do what you need now.

1 Like

I came up with an idea, while looking through the blockly code, I found that the capture block calls domicroscopeaction/camera/capture. I thought of the idea that in addition to doing that, it could also turn on the LED, call the function, and turn off the LED. I also saw that in js you can control the gpio pins of the Raspberry, but I don’t know how to implement it because I don’t have much programming knowledge. Any suggestions?

There is not a simple way to do that without programming, unfortunately.

You are right that Blockly gives the Javascript code which is what actually runs. It is then possible to take that script and run it alone, and actions could be added at that point. However that would require two things - programming in Javascript and functions that can be used to control GPIO. If the script is running on the Pi itself that is possible.

However that approach is not very different from writing a Python program using the Openflexure Python client and Raspberry Pi GPIO libraries in Python. Again it requires programming, but Python is generally considered simpler to use than Javascript, and it needs to be running on the Pi to access the GPIO.

To use the GPIO from a remote computer would need additional functions in the microscope API that can be called as http requests. This thread has come at a point where we are thinking about auxiliary control anyway, so it is part of a discussion of what actual functions we are going to add next. If that gets done, then I can add new blocks in Blockly to expose those functions. Until then it is only really possible using Python (or Javascript).

I did have a look at other timer functions in Blockly that could make your pictures happen at 10 minutes rather than 10 minutes plus the image capture time. I was not able to find anything useful.