Hello,
I recently purchased two RT1062 units to evaluate for a robotics project. I programmed one of the cameras to look for AprilTags and produce a PWM signal when one is found. The RT1062 runs this program just fine when I am connected to the IDE, but it will stop working after 30 or so seconds while running on a 5V-regulated battery. The RT1062 LED is a purple color while the code is working and turns a bluish-white when it stops.
I am not sure if this is a software or hardware issue. A snippet of my code (below) is basically your AprilTag example code with a few lines thrown in to generate PWM signals. Do you know why the RT1062 might run this code well with the IDE, but not when powered by a battery? I’m probably doing something wrong in my code.
# Initialize PWM pin
pwm2 = PWM("P4") # create PWM object from a pin
pwm2.freq(100) # set frequency
duty_cycle = 1
pwm2.duty_u16(duty_cycle) # set duty cycle to zero
# Function to map tag position to duty cycle
def map_duty_cycle(x_pos):
# Map x position range [0, 320] to duty cycle range [0, 100]
#return int(546*(120-abs(x_pos-120))) #HQVGA
return int(819*(80-abs(x_pos-80))) #QQVGA
while True:
img = sensor.snapshot() # Capture a new image
tags = img.find_apriltags(families=tag_families)
if len(tags) == 0:
duty_cycle = 10 # set duty cycle close to zero
pwm2.duty_u16(duty_cycle)
time.sleep(0.5)
else:
# Detect AprilTag(s) in the image
for tag in tags: # defaults to TAG36H11 without "families".
img.draw_rectangle(tag.rect(), color=(255, 0, 0))
img.draw_cross(tag.cx(), tag.cy(), color=(0, 255, 0))
# Extract tag information
tag_id = tag.id()
tag_center_x, tag_center_y = tag.cx(), tag.cy()
# Map tag position to duty cycle
duty_cycle = map_duty_cycle(tag_center_x)
# Update PWM duty cycle
pwm2.duty_u16(duty_cycle)
# Delay time
time.sleep(0.5)

