"Invalid pin" error on Gemma M0

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eat_sleep_code
 
Posts: 64
Joined: Sat Dec 30, 2017 1:30 am

"Invalid pin" error on Gemma M0

Post by eat_sleep_code »

I am building a little fish feeder using a Gemma M0. I wanted to attach a piezo buzzer so I can alert when feeder is empty, etc.

I am getting...

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 13, in <module>
ValueError: Invalid pin
on the following code...

Code: Select all

import time
import board
import pwmio
from adafruit_dotstar import DotStar
from adafruit_motor import servo

### IMPORTANT: Change to your feeding schedule! ###
feedEveryXHours = 12
###################################################

led = DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
servoPin = pwmio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)
piezoPin = pwmio.PWMOut(board.D1, duty_cycle=0, frequency=440, variable_frequency=True)
There is a clearly labeled D1 pin on the board, so what am I doing wrong?

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: "Invalid pin" error on Gemma M0

Post by dastels »


User avatar
eat_sleep_code
 
Posts: 64
Joined: Sat Dec 30, 2017 1:30 am

Re: "Invalid pin" error on Gemma M0

Post by eat_sleep_code »

With D2, I get ...

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 13, in <module>
RuntimeError: All timers in use

User avatar
eat_sleep_code
 
Posts: 64
Joined: Sat Dec 30, 2017 1:30 am

Re: "Invalid pin" error on Gemma M0

Post by eat_sleep_code »

And also get the same error if I user the simpleio library.

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: "Invalid pin" error on Gemma M0

Post by dastels »

Out of curiosity does it work if you set variable_frequency to false? I don't think it will since you don't have another 440Hz timer set up to share.

Dave

User avatar
eat_sleep_code
 
Posts: 64
Joined: Sat Dec 30, 2017 1:30 am

Re: "Invalid pin" error on Gemma M0

Post by eat_sleep_code »

Same error unfortunately. Does the Gemma M0 not support two simultaneous pins using PWM?

User avatar
eat_sleep_code
 
Posts: 64
Joined: Sat Dec 30, 2017 1:30 am

Re: "Invalid pin" error on Gemma M0

Post by eat_sleep_code »

@dastels, here is my full code snippet if it is helpful:

Code: Select all

import time
import board
import pwmio
from adafruit_dotstar import DotStar
from adafruit_motor import servo

### IMPORTANT: Change to your feeding schedule! ###
feedEveryXHours = 12
###################################################

led = DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
servoPin = pwmio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)
piezoPin = pwmio.PWMOut(board.D2, duty_cycle=0, frequency=440, variable_frequency=True)

feederServo = servo.Servo(servoPin)
feederServo.angle = 0
feedServoIncrement = 12


print('Please load food...')
for t in range(30):
    led[0] = (255,255,0)
    time.sleep(0.5)
    led[0] = (0, 0, 0)
    if t > 25:
        piezoPin.frequency = 2620;
        piezoPin.duty_cycle = 65536 // 2
    time.sleep(0.5)
    piezoPin.duty_cycle = 0
        
    
foodAvailable = True
feeding = 0
led[0] = (0,0,255)
    
while foodAvailable == True:
    for angle in range(feedServoIncrement, 180, feedServoIncrement):  
        feeding = feeding + 1
        print('Feeding:', feeding, '|', 'Feeder angle:', angle)
        led[0] = (0,255,0)
        feederServo.angle = angle
        time.sleep(10)
        led[0] = (0,0,255)
        time.sleep((feedEveryXHours * 3600) - 10) # Convert hours to seconds and subtract the 10 seconds we slept above
    feederServo.angle = 0
    foodAvailable = False

print('All out of food!')
led[0] = (255,0,0) 
piezoPin.frequency = 2620;
piezoPin.duty_cycle = 65536 // 2
time.sleep(60)
piezoPin.duty_cycle = 0

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”