According to the product page, there really shouldn’t be a PWM on P6.
The light shield has a permanent PWM pin on P6.
The problem that I am having that at about a 25% duty cycle and lower, it just will not turn on. This has been confirmed with an oscilloscope that nothing happens. Although to be fair I don’t see anything at 50% duty cycle either
Code is here in case curios
from machine import Pin, PWM
import machine
import sensor
import os
import time
pin = Pin("P0", Pin.IN, Pin.PULL_UP)
count = 0
light_pin = Pin("P6", Pin.OUT) # Assuming pin 6 on the RT1062 board
time.sleep(2)
light_pwm = PWM(light_pin, freq=50000, duty_u16=2**16//2)
## Initialize PWM with frequency and duty cycle
#light_pwm.freq(5000) # Frequency of 50kHz
#light_pwm.duty_u16(10000) # 100% duty cycle
def camera_init():
"""
Initialize the camera sensor with specific settings.
This function resets the camera sensor, sets the pixel format to grayscale,
sets the frame size to QVGA, and skips frames to allow the camera to stabilize.
Parameters:
None
Returns:
None
"""
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=1000)
def sdcard_init():
"""
Initialize the SD card for image storage.
This function checks if the 'images' directory exists on the SD card. If it
doesn't, it creates the directory. This directory is used to store images
captured by the camera sensor triggered by interrupts.
Parameters:
None
Returns:
None
"""
if not "images" in os.listdir():
os.mkdir("images") # Make a temp directory
def high_voltage_capture(pin_obj):
"""
Capture an image when triggered by a falling edge interrupt on a pin.
This function is an interrupt handler that captures an image using the camera
sensor when triggered by a falling edge interrupt on the specified pin. It saves
the captured image to the 'images' directory with a filename based on the global
variable 'count', which increments with each capture.
Parameters:
pin_obj : Pin
The Pin object that triggered the interrupt. This argument is passed automatically
by the interrupt system but is not used within the function.
Returns:
None
"""
global count
# Image file name based on count
new_name = f"plastic_perf_{count}.jpg"
# Take photo and save to SD card
img = sensor.snapshot()
img.save("images/" + new_name, quality=90)
count += 1
# Enter Deepsleep Mode (i.e. the OpenMV Cam effectively turns itself off except for the RTC).
#camera setup
camera_init()
#SD card setup
sdcard_init()
#set interrupt for when the high voltage activates
pin.irq(trigger=Pin.IRQ_FALLING, handler=high_voltage_capture)
#turn on the LED shield
#infinite loop waiting for interupt
while(True):
pass
As a bonus is there any way to get the interrupt to only happen once? Every trigger of the interrupt seems to take like 8 pictures for some reason. I have tried time.sleep() but it seems to almost queue the interrupts for whatever reason.