Author Topic: SSTC USB interrupter based on Raspberry Pi Pico  (Read 195 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 Re: Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
davekni
December 01, 2024, 10:45:49 PM
post Re: My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
December 01, 2024, 09:53:13 PM
post Re: My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
LoFoTroFo
December 01, 2024, 03:42:44 PM
post Re: Last cap in CW always blowing up
[Voltage Multipliers]
JoeBusic
December 01, 2024, 03:30:50 PM
post Scientific Atlanta (Cisco) 1 GHz Combiner and PSU Teardown
[Electronic Circuits]
Mads Barnkob
December 01, 2024, 11:43:09 AM
post GU-81M Hartley Driven VTTC
[Vacuum Tube Tesla Coils (VTTC)]
janno288
December 01, 2024, 10:46:59 AM
post Single board for SSTC and DRSSTC operation
[Solid State Tesla Coils (SSTC)]
Simranjit
November 30, 2024, 09:10:38 PM
post Re: My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
November 30, 2024, 07:29:22 PM
post My DRSSTC1 rebuild / Strange GDT ringing
[Dual Resonant Solid State Tesla coils (DRSSTC)]
LoFoTroFo
November 30, 2024, 01:47:58 PM
post Re: Many Multiple Mini Capacitor
[Dual Resonant Solid State Tesla coils (DRSSTC)]
rikkitikkitavi
November 29, 2024, 02:10:44 PM
post Re: Many Multiple Mini Capacitor
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
November 28, 2024, 09:34:29 PM
post Many Multiple Mini Capacitor
[Dual Resonant Solid State Tesla coils (DRSSTC)]
rikkitikkitavi
November 28, 2024, 07:52:42 PM
post Re: Oscilloscope recommendation for SSTC?
[Solid State Tesla Coils (SSTC)]
Simranjit
November 26, 2024, 11:34:05 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
November 25, 2024, 01:03:46 AM
post GU-81M VTTC 2.7MHz Help
[Vacuum Tube Tesla Coils (VTTC)]
janno288
November 24, 2024, 01:53:22 PM
post Re: My SSTC's IGBT's blow up when toroid is added
[Solid State Tesla Coils (SSTC)]
AstRii
November 21, 2024, 07:17:16 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
petespaco
November 20, 2024, 12:11:18 AM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
November 19, 2024, 05:41:27 PM
post Re: Testing and teardown of a commercial induction heater
[Electronic Circuits]
Anders Mikkelsen
November 19, 2024, 01:33:48 PM
post Re: Testing and teardown of a commercial induction heater
[Electronic Circuits]
DashApple
November 19, 2024, 08:02:30 AM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
November 19, 2024, 05:31:47 AM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
futurist
November 19, 2024, 02:33:42 AM
post Re: Testing and teardown of a commercial induction heater
[Electronic Circuits]
dejuli2
November 18, 2024, 11:19:28 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
November 18, 2024, 08:43:20 PM
post Re: Testing and teardown of a commercial induction heater
[Electronic Circuits]
DashApple
November 18, 2024, 06:07:11 PM
post Re: Is intentional overlap in the secondary theoretically possible?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
MinuteMylar
November 18, 2024, 05:04:09 PM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Beggernator.
November 18, 2024, 12:17:41 PM
post Re: Testing and teardown of a commercial induction heater
[Electronic Circuits]
dejuli2
November 18, 2024, 09:25:38 AM
post Re: First DRSSTC, Full Bridge PCB & IGBT Selection question.
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
November 18, 2024, 01:09:10 AM
post Re: 160mm DRSSTC project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
paulsimik
November 17, 2024, 11:36:52 PM
post Re: 160mm DRSSTC project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mathieu thm
November 17, 2024, 10:28:23 PM
post Re: 160mm DRSSTC project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
November 17, 2024, 10:13:44 PM
post Re: IGBT Module / Brick integrity (BSM200GB120DLC) - Help
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
November 17, 2024, 09:15:31 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