Hello!
I'm trying to do an audio project with is basically a rain "sound synthetiser". In fact i have 10 audio track controlled by 10 potentiometers (10k B103 ). By adjusting the volume of each track you kinda will create differents rain textures. I'm also using 2 MCP 3008 to convert the analogic signal for raspberry pi. First MCP got the 8 first tracks, the second MCP got the 2 others tracks and the master control aswell.
Here's the code I use for now:
Not optimised I know but I want it to work before factorising.
Anyway everything was kinda working just fine so far. I was testing each potentiometer individually and got a value between 0,00 and 1,00
Problame came when i decided to solder my 11 potentiometer together. The signal of each potentiometer goes to an MCP entry, however my ground and my 5v is now share between all of them (I believe it's called in parallel?)
Anyway, now each the values read by the program for each track are weird. For testing i only have 8 potentiometers soldered adn in low position.
I exepect my values to be [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00]. But instead i got [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.51] even if my 8th pot is in low position. In the same way, having only the first pot in high position got me something like [0.98, 0.6, 0.6, 0.6, 0.6, 0.6, 0.8]
I should also add the 5v also powering the 2 MCPs aswell as the 11 pots
As you can probably now, I'm a beginner in electronic (an also not an english speacker) and i'm pretty sure connecting the 5v to all my potentiometer created a dependance between them. I'm sure there's a way to fix this but I don't know how. Can you please explian me how to do and why?
I asked GPT and he advise me to put a 10kΩ between the 5v and signal output of every pot but that seems weird to me.
Can eventually take pictures of the project but it's pretty messy with the MCP still on breadboard
Thank you!
I'm trying to do an audio project with is basically a rain "sound synthetiser". In fact i have 10 audio track controlled by 10 potentiometers (10k B103 ). By adjusting the volume of each track you kinda will create differents rain textures. I'm also using 2 MCP 3008 to convert the analogic signal for raspberry pi. First MCP got the 8 first tracks, the second MCP got the 2 others tracks and the master control aswell.
Here's the code I use for now:
Code:
from os import environfrom random import randintfrom gpiozero import MCP3008, Buttonfrom signal import pauseenviron['PYGAME_HIDE_SUPPORT_PROMPT']='1'import pygame, sys, time, mathpygame.mixer.init()pygame.mixer.set_num_channels(10)pygame.init()#ELEC#num_channels = 8#pot_channels_1 = [MCP3008(channel=i, select_pin=8) for i in range(num_channels)]#pot_channels_2 = [MCP3008(channel=i, select_pin=7) for i in range(2)]pot_channel_1 = MCP3008(channel=0, select_pin=8)pot_channel_2 = MCP3008(channel=1, select_pin=8)pot_channel_3 = MCP3008(channel=2, select_pin=8)pot_channel_4 = MCP3008(channel=3, select_pin=8)pot_channel_5 = MCP3008(channel=4, select_pin=8)pot_channel_6 = MCP3008(channel=5, select_pin=8)pot_channel_7 = MCP3008(channel=6, select_pin=8)pot_channel_8 = MCP3008(channel=7, select_pin=8)pot_channel_9 = MCP3008(channel=0, select_pin=7)pot_channel_10 = MCP3008(channel=1, select_pin=7)pot_channel_11 = MCP3008(channel=2, select_pin=7)buttons = { 16: Button(16), 20: Button(20), 21: Button(21)}start_times = {pin: 0 for pin in buttons}press_durations = {pin: 0 for pin in buttons}#SOFTWAREtrack_base_name = "tent"track_format =".mp3"max_number_slices = 70track_name=""filename = 'setup.txt'preset_mode = Falsetrack1_slice_number = 0track2_slice_number = 0track3_slice_number = 0track4_slice_number = 0track5_slice_number = 0track6_slice_number = 0track7_slice_number = 0track8_slice_number = 0track9_slice_number = 0track10_slice_number = 0channel1 = pygame.mixer.Channel(0)channel2 = pygame.mixer.Channel(1)channel3 = pygame.mixer.Channel(2)channel4 = pygame.mixer.Channel(3)channel5 = pygame.mixer.Channel(4)channel6 = pygame.mixer.Channel(5)channel7 = pygame.mixer.Channel(6)channel8 = pygame.mixer.Channel(7)channel9 = pygame.mixer.Channel(8)channel10 = pygame.mixer.Channel(9)#pygame.mixer.music.load("1.wav")#pygame.mixer.music.unload()#pygame.mixer.music.play()#pygame.mixer.music.set_volume(0.5)def on_button_pressed(pin): global start_times start_times[pin] = time.time()def on_button_released(pin): global start_times, press_durations press_durations[pin] = time.time() - start_times[pin] if press_durations[pin] < 3: print(f"Appui court détecté sur le bouton {pin}: {press_durations[pin]:.2f} secondes") preset_mode = True if pin == 16: print("Chargement preset sauvé 1") channels[0][0].set_volume(values[0][0]) channels[1][0].set_volume(values[0][1]) channels[2][0].set_volume(values[0][2]) channels[3][0].set_volume(values[0][3]) channels[4][0].set_volume(values[0][4]) channels[5][0].set_volume(values[0][5]) channels[6][0].set_volume(values[0][6]) channels[7][0].set_volume(values[0][7]) channels[8][0].set_volume(values[0][8]) channels[9][0].set_volume(values[0][9]) elif pin == 20: print("Chargement preset sauvé 2") channels[0][0].set_volume(values[1][0]) channels[1][0].set_volume(values[1][1]) channels[2][0].set_volume(values[1][2]) channels[3][0].set_volume(values[1][3]) channels[4][0].set_volume(values[1][4]) channels[5][0].set_volume(values[1][5]) channels[6][0].set_volume(values[1][6]) channels[7][0].set_volume(values[1][7]) channels[8][0].set_volume(values[1][8]) channels[9][0].set_volume(values[1][9]) else: print("Chargement preset sauvé 3") channels[0][0].set_volume(values[2][0]) channels[1][0].set_volume(values[2][1]) channels[2][0].set_volume(values[2][2]) channels[3][0].set_volume(values[2][3]) channels[4][0].set_volume(values[2][4]) channels[5][0].set_volume(values[2][5]) channels[6][0].set_volume(values[2][6]) channels[7][0].set_volume(values[2][7]) channels[8][0].set_volume(values[2][8]) channels[9][0].set_volume(values[2][9]) else: print(f"Appui long détecté sur le bouton {pin}: {press_durations[pin]:.2f} secondes") if pin == 16: print("Sauvegarde sur preset 1") values[0][0] = channels_volume[0] values[0][1] = channels_volume[1] values[0][2] = channels_volume[2] values[0][3] = channels_volume[3] values[0][4] = channels_volume[4] values[0][5] = channels_volume[5] values[0][6] = channels_volume[6] values[0][7] = channels_volume[7] values[0][8] = channels_volume[8] values[0][9] = channels_volume[9] elif pin == 20: print("Sauvegarde sur preset 2") values[1][0] = channels_volume[0] values[1][1] = channels_volume[1] values[1][2] = channels_volume[2] values[1][3] = channels_volume[3] values[1][4] = channels_volume[4] values[1][5] = channels_volume[5] values[1][6] = channels_volume[6] values[1][7] = channels_volume[7] values[1][8] = channels_volume[8] values[1][9] = channels_volume[9] else: print("Sauvegarde sur preset 3") values[2][0] = channels_volume[0] values[2][1] = channels_volume[1] values[2][2] = channels_volume[2] values[2][3] = channels_volume[3] values[2][4] = channels_volume[4] values[2][5] = channels_volume[5] values[2][6] = channels_volume[6] values[2][7] = channels_volume[7] values[2][8] = channels_volume[8] values[2][9] = channels_volume[9] save_values(filename,values) def read_values(filename): # Ouvrir le fichier en mode lecture with open(filename, 'r') as file: lines = file.readlines() values = [] for line in lines: # Séparer les valeurs dans chaque série par la virgule et les convertir en flottants values.append([float(val) for val in line.strip().split(',')]) return valuesdef save_values(filename, values): # Préparer le contenu à écrire en formatant les valeurs series_strings = [] for serie in values: series_strings.append(','.join(f"{value:.2f}" for value in serie)) content = '\n'.join(series_strings) # Ouvrir le fichier en mode écriture with open(filename, 'w') as file: file.write(content)def queueNextSlice(channel,track_number, track_slice_number): if track_slice_number+1==max_number_slices: track_slice_number=0 else: track_slice_number+=1 track_name=track_base_name+track_number+"s"+str(track_slice_number)+track_format track_slice=pygame.mixer.Sound(track_name) print("QEUEING :"+track_name) channel.queue(track_slice) time.sleep(180/10) return(track_slice_number)def initialReading(channel,track_number, track_slice_number): track_name=track_base_name+str(track_number)+"s"+str(track_slice_number)+track_format track_slice=pygame.mixer.Sound(track_name) print("INITIAL READING :"+track_name) channel.play(track_slice,fade_ms=1000)def adjust_potentiometer_value(raw_value, min_val=0.38, max_val=1.00, exponent=2): # Vérifiez que la valeur brute est dans l'intervalle [min_val, max_val] if raw_value < min_val: raw_value = min_val elif raw_value > max_val: raw_value = max_val # Normaliser la valeur brute à une échelle de 0 à 1 normalized_value = (raw_value - min_val) / (max_val - min_val) # Appliquer une transformation exponentielle pour ajuster la courbe adjusted_value = normalized_value ** exponent return round(adjusted_value,2)channels = []channels_volume = []for i in range(10): # Vous pouvez remplacer les valeurs suivantes par celles que vous souhaitez utiliser if i ==0: channel=channel1 elif i ==1: channel=channel2 elif i ==2: channel=channel3 elif i ==3: channel=channel4 elif i ==4: channel=channel5 elif i ==5: channel=channel6 elif i ==6: channel=channel7 elif i ==7: channel=channel8 elif i ==8: channel=channel9 elif i ==9: channel=channel10 track_slice_number = randint(0,max_number_slices-1) channel_info = [channel, str(i+1), track_slice_number] channels.append(channel_info) for i in range(11): channels_volume.append(0.0)initialReading(channels[0][0],channels[0][1],channels[0][2])initialReading(channels[1][0],channels[1][1],channels[1][2])initialReading(channels[2][0],channels[2][1],channels[2][2])initialReading(channels[3][0],channels[3][1],channels[3][2])initialReading(channels[4][0],channels[4][1],channels[4][2])initialReading(channels[5][0],channels[5][1],channels[5][2])initialReading(channels[6][0],channels[6][1],channels[6][2])initialReading(channels[7][0],channels[7][1],channels[7][2])initialReading(channels[8][0],channels[8][1],channels[8][2])initialReading(channels[9][0],channels[9][1],channels[9][2])values = read_values(filename)print(f"Valeurs setup 1 : {values[0]}")print(f"Valeurs setup 2 : {values[1]}")print(f"Valeurs setup 3 : {values[2]}")channels[0][0].set_volume(values[0][0])channels[1][0].set_volume(values[0][1])channels[2][0].set_volume(values[0][2])channels[3][0].set_volume(values[0][3])channels[4][0].set_volume(values[0][4])channels[5][0].set_volume(values[0][5])channels[6][0].set_volume(values[0][6])channels[7][0].set_volume(values[0][7])channels[8][0].set_volume(values[0][8])channels[9][0].set_volume(values[0][9])while True: #channels[0][2]=queueNextSlice(channels[0][0],channels[0][1],channels[0][2]) #channels[1][2]=queueNextSlice(channels[1][0],channels[1][1],channels[1][2]) #channels[2][2]=queueNextSlice(channels[2][0],channels[2][1],channels[2][2]) #channels[3][2]=queueNextSlice(channels[3][0],channels[3][1],channels[3][2]) #channels[4][2]=queueNextSlice(channels[4][0],channels[4][1],channels[4][2]) #channels[5][2]=queueNextSlice(channels[5][0],channels[5][1],channels[5][2]) #channels[6][2]=queueNextSlice(channels[6][0],channels[6][1],channels[6][2]) #channels[7][2]=queueNextSlice(channels[7][0],channels[7][1],channels[7][2]) #channels[8][2]=queueNextSlice(channels[8][0],channels[8][1],channels[8][2]) #channels[9][2]=queueNextSlice(channels[9][0],channels[9][1],channels[9][2]) raw_value = pot_channel_1.value channels_volume[0] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_2.value channels_volume[1] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_3.value channels_volume[2] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_4.value channels_volume[3] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_5.value channels_volume[4] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_6.value channels_volume[5] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_7.value channels_volume[6] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_8.value channels_volume[7] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_9.value channels_volume[8] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_10.value channels_volume[9] = round(1-adjust_potentiometer_value(raw_value),2) raw_value = pot_channel_11.value global_volume = round(1-adjust_potentiometer_value(raw_value),2) # Affichage de la valeur lue print(channels_volume , "global :", global_volume) for vol in range(10): channels[vol][0].set_volume(channels_volume[vol]*global_volume) # Attente avant la prochaine lecture #channels[3][0].set_volume(linear_value) for pin, button in buttons.items(): button.when_pressed = lambda pin=pin: on_button_pressed(pin) button.when_released = lambda pin=pin: on_button_released(pin) time.sleep(0.1)
Anyway everything was kinda working just fine so far. I was testing each potentiometer individually and got a value between 0,00 and 1,00
Problame came when i decided to solder my 11 potentiometer together. The signal of each potentiometer goes to an MCP entry, however my ground and my 5v is now share between all of them (I believe it's called in parallel?)
Anyway, now each the values read by the program for each track are weird. For testing i only have 8 potentiometers soldered adn in low position.
I exepect my values to be [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00]. But instead i got [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.51] even if my 8th pot is in low position. In the same way, having only the first pot in high position got me something like [0.98, 0.6, 0.6, 0.6, 0.6, 0.6, 0.8]
I should also add the 5v also powering the 2 MCPs aswell as the 11 pots
As you can probably now, I'm a beginner in electronic (an also not an english speacker) and i'm pretty sure connecting the 5v to all my potentiometer created a dependance between them. I'm sure there's a way to fix this but I don't know how. Can you please explian me how to do and why?
I asked GPT and he advise me to put a 10kΩ between the 5v and signal output of every pot but that seems weird to me.
Can eventually take pictures of the project but it's pretty messy with the MCP still on breadboard
Thank you!
Statistics: Posted by Nikolls — Tue Jul 23, 2024 3:16 pm