Page 1 of 1

Microcontroller adjusting voltage of laser module

Posted: Sat Dec 04, 2021 3:45 pm
by wouterjesse
Hi there,

I'm a total newbie in the field of microcontrollers and MicroPython.

I have a small project in mind in which I would like to make a laser module pulse very very slowly. Bringing up and down the voltage from 0V to 5V and back.

The laser module is already connected to the controller. I can turn it on/off and blink, but I would like to have more control over the voltage and time.

Is there somebody who can point me in a direction where to look or even has a solution for me to use?

Thank you,

Wouter

Re: Microcontroller adjusting voltage of laser module

Posted: Sun Dec 05, 2021 11:05 am
by pythoncoder
You need a DAC (digital to analog converter). Some MicroPython targets have these built-in (e.g. Pyboards). Otherwise they can be bought or built using a resistor network and an op amp - but this needs some skill in electronic construction.

But the firs step is to determine if your laser module is characterised to work at low voltages. It's possible that it won't "lase" until the voltage reaches a threshold. If you want to vary its brightness you may need to pulse it at high frequency, varying the duty ratio. But cheap laser modules don't like this either...

Re: Microcontroller adjusting voltage of laser module

Posted: Sun Dec 05, 2021 3:38 pm
by wouterjesse
Thank you for your reply.

Unfortunately, the Raspberry Pico doesn't have a built-in DAC.
Although it has a built-in PWM. Would it be possible to create a sin-wave with the PWM?

Re: Microcontroller adjusting voltage of laser module

Posted: Sun Dec 05, 2021 4:32 pm
by wouterjesse
I have found this code that works by fading the laser in and out.

But I can't seem to find where to adjust the code and make the fade in and out slower.

Code: Select all

led = Pin(20)
pwm = PWM(led)

pwm.freq(1000)

duty = 0
direction = 1
for repeat in range (2000):
    duty += direction
    if duty > 200:
        duty = 200
        direction = -1
    elif duty < 0:
        duty = 0
        direction = 1
        
    pwm.duty_u16(duty * duty)
    utime.sleep(0.01)  

Re: Microcontroller adjusting voltage of laser module

Posted: Sun Dec 05, 2021 6:51 pm
by pythoncoder
Try adjusting the sleep time - utime.sleep(0.01)

Re: Microcontroller adjusting voltage of laser module

Posted: Mon Dec 06, 2021 11:58 am
by wouterjesse
Amazing, what fun to play around with microcontrollers and micropython.

Thank you for the support!