In this guide, we’ll focus on controlling the CoilCell's polarity and magnetic field strength, making it ideal for applications like flip-dot mechanical pixel and other magnetic pixels.
CoilCell operates by passing current through its coil, generating a magnetic field whose polarity depends on the current direction. Since CoilCell has an integrated H-bridge, it can directly control the coil’s polarity and strength without requiring an external driver, like DriveCell.
Instead of simply turning the coil on or off, we’ll use Pulse Width Modulation (PWM) to finely adjust the magnetic strength and flip polarity as needed.
Several factors affect polarity control and field strength:
Remember CoilCell is available in two configurations:
If you're using the CoilCell library, the following example demonstrates how to flip polarity and adjust strength:
#include <CoilCell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
void setup() {
myCoilCell.Init();
}
void loop() {
myCoilCell.Drive(true, 100); // Strong north pole field
delay(3000);
myCoilCell.Drive(false, 100); // Strong south pole field
delay(3000);
myCoilCell.Drive(true, 50); // Weaker north pole field
delay(3000);
myCoilCell.Drive(false, 50); // Weaker south pole field
delay(3000);
}
⚠ Note: The Drive
()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
Init()
→ Initializes CoilCell and sets up the control pins.Drive(bool direction, uint8_t power_percent)
true
(north pole) / false
(south pole)By alternating polarity, CoilCell can be used to flip magnetic elements, such a flipdot pixel combined with a magnet. To smooth this out, we can use Pulse Width Modulation (PWM) on both outputs. This method gradually changes the magnetic field intensity, reducing mechanical stress on the CoilCell.
This function is automatically handled within our CoilCell library:
#include <coilcell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
uint16_t vibration_counter = 0;
void setup() {
myCoilCell.Init();
myCoilCell.Tone();
}
void loop() {
myCoilCell.Vibrate(1, 75, 1000); // Flip at 75% power every 1sec
}
Init()
→ Initializes CoilCell and sets up the input pins.Vibrate(smooth, power, speed_ms)
→ Oscillates the CoilCell in either a square wave or a smoother PWM wave.
smooth
→ 1 (PWM wave) / 0 (square wave)power
→ Magnetic-field strength (0 to 100%)speed_ms
→ Vibration speed in milliseconds⚠ Note: The Vibrate
()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
With these techniques, you can start controlling CoilCell's magnetic polarity. Check out the CoilCell GitHub Repository for more code examples and technical documentation!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.