Author Topic: SSTC USB interrupter based on Raspberry Pi Pico  (Read 223 times)

Offline AdamRozdrazewski

  • High Voltage Enthusiast
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
SSTC USB interrupter based on Raspberry Pi Pico
« on: October 25, 2024, 10:28:43 AM »
Hello

Lately i build simple USB interrupter on Pi pico and want to share my code and ask for help. Its quite messy but works.
There is no ontime regulation. To achieve polyphonic ive been using IC OR gate to add up signals(don't know how to code it). Im asking for advice how to add these featuers and make interrupter safe for drsstc. Its based on circuitpython midi library
Code: [Select]
import random
import time
import pwmio
import usb_midi
import board
import adafruit_midi
from adafruit_midi.control_change import ControlChange
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend
from analogio import AnalogIn



# GLOBAL VARIABLES
freq = 100
current_duty_cycle2 = 0
notes_table = []
notes_state = [0] * 128
latest_on_tmp = 0
last_position1 = 0
last_position2 = 0
playing = True


analog_in1 = AnalogIn(board.A1)
analog_in2 = AnalogIn(board.A2)
analog_in3 = AnalogIn(board.A0)

factor1 = 1
frequency1 = 100
factor2 = 1
frequency2 = 100

pwm3 = pwmio.PWMOut(board.GP13, duty_cycle=0, frequency=100, variable_frequency=True)
pwm4 = pwmio.PWMOut(board.GP9, duty_cycle=0, frequency=100, variable_frequency=True)
print(usb_midi.ports)
midi = adafruit_midi.MIDI(
    midi_in=usb_midi.ports[0], in_channel=(0,1,2,3), midi_out=usb_midi.ports[1], out_channel=0
)
print("Midi test")
print("Default output channel:", midi.out_channel + 1)
print("Listening on input channel:", midi.in_channel[0] + 1, " and ", midi.in_channel[0] + 1)

def note_to_herz(control):
    return int(notes_table[control])

def create_table():
    a = 440.0
    for x in range(0,127):
       notes_table.append((a / 32.0) * (2.0 ** ((x - 9) / 12.0)))
create_table()
while True:

      time.sleep(0.0005)
      dc1 = int(analog_in1.value / 3) #reading values from potentiometers range is from 0 to 65535
      dc2 = int(analog_in2.value / 3) #max 33% duty cycle
     

      if dc1 <= 300:    ## fixing ADC's 0
          dc1 = 0
      if dc2 <= 300:
          dc2 = 0
       
     

      msg = midi.receive()
      if msg is not None:
          print("Received:", msg, "at", time.monotonic())
          if msg.channel == 0:  ## channel 1
              if (isinstance(msg, PitchBend)):
                  pitch = msg.pitch_bend
                  factor1 = 2**((pitch - 8192) / 8192)
                  pwm3.frequency = int(frequency1 * factor1)
                  pwm3.duty_cycle = dc1
                  playing = True
                  print("PITCH: ", pitch, "PITCH: ", factor1)
              elif (isinstance(msg, NoteOn)):
                  notes_state[msg.note] = 1
                  latest_on_tmp = time.monotonic()
                  pwm3.frequency = int(float(note_to_herz(msg.note) * factor1))
                  frequency1 = pwm3.frequency
                  pwm3.duty_cycle = dc1
                  playing = True
                  print("[CH1] NOTE ", msg.note, " ON with FREQ: ", str(pwm3.frequency), "Hz at", time.monotonic())
              elif (isinstance(msg, NoteOff)):
                  notes_state[msg.note] = 0
                  pwm3.duty_cycle = 0
                  print("NOTE ", msg.note, " OFF AT CHANNEL ", msg.channel, " with FREQ: ", str(note_to_herz(msg.note)), "Hz at", time.monotonic())
          elif msg.channel == 1:  ## channel 2
              if (isinstance(msg, PitchBend)):
                  pitch = msg.pitch_bend
                  factor2 = 2**((pitch - 8192) / 8192)
                  pwm4.frequency = int(frequency2 * factor2)
                  pwm4.duty_cycle = dc2
                  playing = True
                  print("PITCH: ", pitch, "PITCH: ", factor2)
              elif (isinstance(msg, NoteOn)):
                  notes_state[msg.note] = 1
                  latest_on_tmp = time.monotonic()
                  pwm4.frequency = int(float(note_to_herz(msg.note) * factor2))
                  frequency2 = pwm4.frequency
                  pwm4.duty_cycle = dc2
                  playing = True
                  print("[CH2] NOTE ", msg.note, " ON with FREQ: ", str(pwm4.frequency), "Hz at", time.monotonic())
              elif (isinstance(msg, NoteOff)):
                  notes_state[msg.note] = 0
                  pwm4.duty_cycle = 0
                  print("NOTE ", msg.note, " OFF AT CHANNEL ", msg.channel, " with FREQ: ", str(note_to_herz(msg.note)), "Hz at", time.monotonic())
      if ((latest_on_tmp + 0.5) < time.monotonic()) and playing:  ## fixing bug when stoping music from midi program
          for note in notes_state:
            notes_state[note] = 0
          pwm3.duty_cycle = 0
          pwm4.duty_cycle = 0
          playing = False
          print("[TIMEOUT] OFF with all FREQs at", time.monotonic())
« Last Edit: October 25, 2024, 10:30:23 AM by AdamRozdrazewski »

High Voltage Forum

SSTC USB interrupter based on Raspberry Pi Pico
« on: October 25, 2024, 10:28:43 AM »

 


* Recent Topics and Posts

post Ferrite transformer from Microwave
[Transformer (Ferrite Core)]
Simranjit
Today at 11:37:35 PM
post Re: Measuring the coherence length of a laser
[Light, Lasers and Optics]
alan sailer
December 07, 2024, 09:41:37 PM
post Re: Measuring the coherence length of a laser
[Light, Lasers and Optics]
haversin
December 07, 2024, 07:07:49 PM
post Re: Measuring the coherence length of a laser
[Light, Lasers and Optics]
alan sailer
December 07, 2024, 06:33:32 PM
post Re: Measuring the coherence length of a laser
[Light, Lasers and Optics]
haversin
December 07, 2024, 06:13:56 PM
post Re: Measuring the coherence length of a laser
[Light, Lasers and Optics]
alan sailer
December 07, 2024, 02:40:55 AM
post Measuring the coherence length of a laser
[Light, Lasers and Optics]
haversin
December 07, 2024, 01:07:46 AM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
davekni
December 07, 2024, 12:18:49 AM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
Simranjit
December 06, 2024, 11:59:05 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
December 06, 2024, 11:33:05 PM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
davekni
December 06, 2024, 11:28:25 PM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
GaelJaton
December 06, 2024, 09:47:04 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
December 06, 2024, 08:06:27 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
December 06, 2024, 07:54:01 PM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
Simranjit
December 06, 2024, 03:54:00 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Beggernator.
December 06, 2024, 02:38:56 PM
post Re: GU-81M Hartley Driven VTTC
[Vacuum Tube Tesla Coils (VTTC)]
janno288
December 06, 2024, 12:20:40 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
December 06, 2024, 12:20:17 AM
post Re: Syntherrupter - Help and Issues
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
thosa
December 05, 2024, 11:07:37 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
December 05, 2024, 10:33:09 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
December 05, 2024, 08:49:35 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
December 05, 2024, 08:36:20 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Beggernator.
December 05, 2024, 04:02:30 PM
post Re: GU-81M Hartley Driven VTTC
[Vacuum Tube Tesla Coils (VTTC)]
Mads Barnkob
December 05, 2024, 09:06:07 AM
post Re: GU-81M Hartley Driven VTTC
[Vacuum Tube Tesla Coils (VTTC)]
Twospoons
December 05, 2024, 03:42:56 AM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
December 04, 2024, 07:50:31 PM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
Anders Mikkelsen
December 04, 2024, 06:32:46 PM
post Re: GU-81M Hartley Driven VTTC
[Vacuum Tube Tesla Coils (VTTC)]
Mads Barnkob
December 04, 2024, 09:31:08 AM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
ZakW
December 04, 2024, 01:02:47 AM
post Re: My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
December 03, 2024, 10:47:15 PM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
davekni
December 03, 2024, 10:38:40 PM
post Re: My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
LoFoTroFo
December 03, 2024, 07:38:24 PM
post Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
Anders Mikkelsen
December 03, 2024, 06:27:28 PM

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 
SimplePortal 2.3.6 © 2008-2014, SimplePortal