Uploaded March 2025 | Updated December 2026, 1 day ago
diy PEMF DEVICE and PI4 GPIO pinS PYTHON SCRIPT - raspberry pi PEMF controller that controls a PEMF DEVICE - a HV capacitive discharge circuit that uses an SCR that dumps the cap joules into a PEMF COIL, controlled by the python script triggering /PI4 GPIO pins, setup uses 2 solid state relays,
1 that turns on and off the power to the cap discharge circuit...which shuts down the SCR by removing power to the PEMF CHARGING CIRCUIT for 2 to 3 milliseconds after each PULSE /after SCR gate gets triggered by GPIO PWM PIN 18 through a 2nd SSR connected to the SCR GATE/
this PYTHON SCRIPT controls the PEMF frequency pulse rate , activating the ON/OFF power to the circuit by GPIO PIN 19 and triggering the SCR GATE by GPIO PIN 18 : https://u.pcloud.link/publink/show?code=XZ5kS45Z5OoqFwOk5bfLKGmahXypVF83qtgy
UPDATE: here is an upgraded by GROK3 & GPT4 script with supposed better code construction, better safe guards , lower by half the pi cpu, etc...does the same thing etc.. https://u.pcloud.link/publink/show?code=XZ83S45ZNm4qsMnUWmb8Md3u92WK4LSg9d7k
python script description from chatGPT:
This Python script is designed to generate a frequency sweep on a Raspberry Pi’s GPIO pins using the pigpio library. It controls two pins: one (PWM_GPIO on pin 18) outputs a PWM signal, and the other (SYNC_GPIO on pin 19) provides a synchronized signal. Here’s a breakdown of its functionality and performance:
---
### What It Does
1. **Command-Line Input & Validation**
- **Arguments:** The script expects four command-line arguments:
- **sweep_duration:** Total time over which the frequency sweep occurs.
- **min_freq & max_freq:** The lower and upper frequency limits for the sweep.
- **pulse_width_us:** The duration of the high pulse (in microseconds) for the PWM signal.
- **Validation:** It checks that all values are positive and that the minimum frequency does not exceed the maximum. If not, the program prints usage instructions and exits.
2. **Initialization and Setup**
- **pigpio Connection:** It initializes a connection to the pigpio daemon. If the connection fails, the script exits.
- **GPIO Configuration:** It sets up GPIO pins 18 and 19 as outputs and initializes them to a low state.
3. **Waveform Generation (Frequency Sweep)**
- **Frequency Sequence:**
- The script creates a frequency sequence that first sweeps upward (from *min_freq* to *max_freq*) and then downward back to *min_freq*.
- For each frequency, it calculates the period (in microseconds) and determines the number of cycles needed to cover the time slice for that frequency step.
- **Pulse Construction:**
- For each cycle at a given frequency, it constructs a series of pigpio pulses:
- A delay (1000 µs) with the SYNC pin off.
- A high pulse on the PWM pin for the specified pulse width.
- Another delay (1000 µs) turning the PWM pin off.
- A final delay (period minus the fixed delays) with the SYNC pin on.
- **Segmenting the Waveform:**
- If the total number of pulses is small enough (under a set maximum), the script creates a single waveform segment.
- If too many pulses are generated, it splits them into multiple segments to stay within pigpio’s limits.
4. **Waveform Transmission**
- **Single-Segment Mode:** The script repeatedly sends the waveform using pigpio’s `wave_send_repeat` function.
- **Multi-Segment Mode:** It chains segments manually, sending one after the other while checking that each segment finishes before moving to the next.
- **User Interruption:** A separate thread waits for the user to press Enter or catch a Ctrl+C (SIGINT) signal. When detected, a global stop event is triggered.
5. **Shutdown Sequence**
- Once the stop event is set, the script stops the current waveform.
- It then sends a final “shutdown” sequence consisting of 15 low-frequency pulses on the PWM pin to gracefully signal the end of operation.
- Finally, it cleans up by stopping pigpio, ensuring the GPIO pins are reset.
diy PEMF DEVICE and PI4 GPIO pinS PYTHON SCRIPT - raspberry pi PEMF controller that controls a PEMF DEVICE - a HV capacitive discharge circuit that uses an SCR that dumps the cap joules into a PEMF COIL, controlled by the python script triggering /PI4 GPIO pins, setup uses 2 solid state relays,
1 that turns on and off the power to the cap discharge circuit...which shuts down the SCR by removing power to the PEMF CHARGING CIRCUIT for 2 to 3 milliseconds after each PULSE /after SCR gate gets triggered by GPIO PWM PIN 18 through a 2nd SSR connected to the SCR GATE/
this PYTHON SCRIPT controls the PEMF frequency pulse rate , activating the ON/OFF power to the circuit by GPIO PIN 19 and triggering the SCR GATE by GPIO PIN 18 : https://u.pcloud.link/publink/show?code=XZ5kS45Z5OoqFwOk5bfLKGmahXypVF83qtgy
UPDATE: here is an upgraded by GROK3 & GPT4 script with supposed better code construction, better safe guards , lower by half the pi cpu, etc...does the same thing etc.. https://u.pcloud.link/publink/show?code=XZ83S45ZNm4qsMnUWmb8Md3u92WK4LSg9d7k
python script description from chatGPT:
This Python script is designed to generate a frequency sweep on a Raspberry Pi’s GPIO pins using the pigpio library. It controls two pins: one (PWM_GPIO on pin 18) outputs a PWM signal, and the other (SYNC_GPIO on pin 19) provides a synchronized signal. Here’s a breakdown of its functionality and performance:
---
### What It Does
1. **Command-Line Input & Validation**
- **Arguments:** The script expects four command-line arguments:
- **sweep_duration:** Total time over which the frequency sweep occurs.
- **min_freq & max_freq:** The lower and upper frequency limits for the sweep.
- **pulse_width_us:** The duration of the high pulse (in microseconds) for the PWM signal.
- **Validation:** It checks that all values are positive and that the minimum frequency does not exceed the maximum. If not, the program prints usage instructions and exits.
2. **Initialization and Setup**
- **pigpio Connection:** It initializes a connection to the pigpio daemon. If the connection fails, the script exits.
- **GPIO Configuration:** It sets up GPIO pins 18 and 19 as outputs and initializes them to a low state.
3. **Waveform Generation (Frequency Sweep)**
- **Frequency Sequence:**
- The script creates a frequency sequence that first sweeps upward (from *min_freq* to *max_freq*) and then downward back to *min_freq*.
- For each frequency, it calculates the period (in microseconds) and determines the number of cycles needed to cover the time slice for that frequency step.
- **Pulse Construction:**
- For each cycle at a given frequency, it constructs a series of pigpio pulses:
- A delay (1000 µs) with the SYNC pin off.
- A high pulse on the PWM pin for the specified pulse width.
- Another delay (1000 µs) turning the PWM pin off.
- A final delay (period minus the fixed delays) with the SYNC pin on.
- **Segmenting the Waveform:**
- If the total number of pulses is small enough (under a set maximum), the script creates a single waveform segment.
- If too many pulses are generated, it splits them into multiple segments to stay within pigpio’s limits.
4. **Waveform Transmission**
- **Single-Segment Mode:** The script repeatedly sends the waveform using pigpio’s `wave_send_repeat` function.
- **Multi-Segment Mode:** It chains segments manually, sending one after the other while checking that each segment finishes before moving to the next.
- **User Interruption:** A separate thread waits for the user to press Enter or catch a Ctrl+C (SIGINT) signal. When detected, a global stop event is triggered.
5. **Shutdown Sequence**
- Once the stop event is set, the script stops the current waveform.
- It then sends a final “shutdown” sequence consisting of 15 low-frequency pulses on the PWM pin to gracefully signal the end of operation.
- Finally, it cleans up by stopping pigpio, ensuring the GPIO pins are reset.










