Menu
Microbots
0
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • English
  • Your Cart is Empty
Microbots
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

Learn

MotorCell Basics: Your First Steps

MotorCell Basics: Your First Steps

MotorCell is an ultra-compact, shaftless PCB motor designed for high-speed, low-torque applications. With its innovative pancake design and planar PCB windings, MotorCell is perfect for robotics, art installations, and DIY projects. This motor simplifies integration by using sensorless control with PWM speed adjustments.

Full Video Tutorial Coming Soon

In this tutorial, we’ll cover:

  • What is MotorCell and how does it work?
  • Setting up your MotorCell
  • Getting started with its Arduino library
  • Example projects to bring MotorCell to life

What is MotorCell?

The MotorCell reimagines motor design by integrating the rotor, stator and driver, into a single, flat PCB. This unique structure:

  • Reduces size to just a few millimeters in thickness.
  • Provides speed control via PWM and also speed feedback.
  • Operates sensorlessly, meaning fewer components and easier setup.
  • Simplifies integration with standard pitch pins.

MotorCell is ideal for applications that require small, lightweight, compact motors, such as small robotics, kinetic art, or even portable gadgets.

Setting Up Your MotorCell

To get started, follow these steps:

  • Connecting Your MotorCell

Pins:

  • IN: Connect to VDD (for full speed) or a PWM-capable GPIO pin on your microcontroller to control motor speed.
  • OUT: Optional for reading the MotorCell's RPM - requires a pull-up resistor (internal-pullup automatically configured by the MotorCell library)
  • FR: Optional to control motor's direction - connect to VDD, GND or to a GPIO pin for forward/reverse switching.
  • GND: Connect to ground pin.
  • VDD: Connect to supply pin 2.5V to 5V
  • Installing the MotorCell Library

Open the Arduino IDE, go to Sketch > Include Library > Manage Libraries, search for "MotorCell," and install it. Then include it in your code and setup your pins:

#include "MotorCell.h"

#define IN_PIN 2
#define OUT_PIN 3
#define FR_PIN 1

MotorCell myMotorCell(IN_PIN, OUT_PIN, FR_PIN);

void setup() {
    myMotorCell.Init(); // Initialize the MotorCell
}

MotorCell Library Functions

Here are the core functions of the MotorCell library:

  • Init(): Sets up the MotorCell for operation.
myMotorCell.Init();
  • Spin(uint8_t speed_percent): Spins the motor at a specified speed (0–100%).
uint16_t rpm = myMotorCell.Spin(50); // Spin at 50% speed
  • SpinPID(uint16_t target_rpm): Maintains a target RPM using PID control (requires ESP32/CodeCell).
uint16_t rpm = myMotorCell.SpinPID(12000); // Maintain 12,000 RPM
  • ReverseSpin(): Reverses the motor’s direction.
myMotorCell.ReverseSpin();
  • Pulse(uint8_t p_pin, uint8_t ms_duration): Sends a short pulse to the specified pin for a given duration (in milliseconds). Useful for quick bursts of motion or momentary signals.

    myMotorCell.Pulse(FR_PIN, 50); // Sends a 50ms pulse to the FR_PIN
    
  • RPMRead(): Reads the motor’s current RPM.
uint16_t currentRPM = myMotorCell.RPMRead();
  • MaxSpin(): Spins the motor at maximum speed.
myMotorCell.MaxSpin();

Example Project: RPM Monitoring

Here’s a simple project to get you started:

#include "MotorCell.h"

#define IN_PIN 2
#define OUT_PIN 3
#define FR_PIN 4

MotorCell myMotorCell(IN_PIN, OUT_PIN, FR_PIN);

void setup() {
    Serial.begin(115200);
    myMotorCell.Init();    
}

void loop() {
    uint16_t rpm = myMotorCell.Spin(50); // Spin at 50% speed
}

More examples available on github, but if you have any questions about MotorCell, feel free to contact us!

Read More

CodeCell Basics: Your First Steps

CodeCell Basics: Your First Steps

If you’ve just got your hands on the CodeCell, you're in for a treat. This tiny module is designed to simplify your DIY projects with multiple features packed into a penny-sized board. In this guide, we’ll walk you through:

  • What makes a CodeCell? And how does it circuit work?
  • How to setup and use your CodeCell
  • Getting started with Examples
  • Explain all the available library functions and how you can use them in your project

What makes a CodeCell?

CodeCell is a compact and versatile module featuring the ESP32-C3, multiple power options, and integrated sensors, all within a tiny 1.85 cm wide form factor. These features make it a powerful tool for a wide range of applications.

In this first section, we'll start by getting familiar with the circuitry that forms the CodeCell. After that, we'll walk through the simple steps to set up your CodeCell.

ESP32C3 Module

At the heart of the CodeCell is the ESP32C3 module, a compact microcontroller known for being maker-friendly in the IoT space. It combines an Arduino-compatible architecture with built-in Wi-Fi and Bluetooth Low Energy (BLE) capabilities. This integration offers the most popular connectivity options while maintaining a small form factor.

The ESP32C3 module's PCB antenna is positioned on one side, away from other components, to minimize interference and improve signal transmission and reception. This placement helps reduce the impact of ground planes or other conductive surfaces that could degrade antenna performance. The components on the bottom side are kept within the recommended clearance for the antenna. From testing we found that the antenna's performance remains unaffected by the minimal interference from a USB-C cable, as these cables are typically shielded.

The ESP32-C3 provides plenty of memory, with 4 MB of Flash and 400 KB of SRAM, making it capable of running most typical applications. Its 32-bit RISC-V single-core processor, running at up to 160 MHz, efficiently handles various tasks. This combination of memory and processing power makes the ESP32-C3 suitable for a wide range of uses.

The ESP32C3 module also supports a USB Serial/JTAG Controller, allowing us to make the CodeCell reflashable through the USB-C port and to send serial data for communication and debugging.

Power Management

The CodeCell offers flexibility in power supply options. It can be powered through the LiPo battery connector, a USB-C cable, or both.

The LiPo battery connector makes it easier than ever to safely connect the battery without the need for soldering or risking accidental shorting it. 

The USB-C port serves dual purposes: it is used for both powering the device and/or reprogramming it. This multi-power option is enabled through the BQ24232 battery management chip, which features dynamic power-path management (DPPM) that can power the system while simultaneously and independently charging the battery. The battery charging process is managed in three phases: conditioning precharge, constant current, and constant voltage. To protect the battery the output voltage (Vo) is regulated though the BQ24232 chip. This output supports a maximum output current of 1500mA when powered by the LiPo battery and 450mA when powered via USB.

By default, the LiPo battery charge current is set to 90mA, ensuring a balanced and a safe charge rate for the optional 170mAh LiPo battery. Further more, for those who wish to adjust the charging rate, 0402 resistor R12 have to be de-soldered and replace it with a new resistor based on the formula (R = 870/Ichrg). This is only recommended for soldering pros, who aren’t afraid of wrestling with tiny 0402 components! Check the BQ24232 datasheet for more information on the battery charging.

The CodeCell library can provides visual feedback on the battery/usb power status via the onboard addressable RGB LED:

  • Low Battery Warning: When the battery voltage drops below 3.3V, the LED blinks red ten times and the device enters Sleep Mode. This helps conserve power until the device is reconnected to a USB charger.
  • Charging Process: During charging, the CodeCell suspends application processes, lights the LED blue, and waits for the battery to reach full charge. Once fully charged, the LED performs a breathing-light animation, indicating proximity distance detected by the sensors.
  • Battery Powered: When the USBC is disconnected and running from the battery power the CodeCell will light green again performing a breathing-light animation, indicating proximity distance detected by the sensors.

The power regulation is further supported by multiple decoupling capacitors, including up to two bulk capacitors of 100µF each, placed next to the battery-connector. These capacitors are connected to the 3.3V and the output Vo pins to ensure stable power delivery. Additionally, the board features two TVS diodes for protection; one safeguards the USB input 5V voltage (Vin), and the other protects the output voltage (Vo). These TVS diodes provide protection against electrostatic discharges (ESD), capable of safely absorbing repetitive ESD strikes above the maximum level specified in the IEC 61000-4-2 international standard without performance degradation.

The board also includes an onboard 3.3V Low Dropout (LDO) regulator, which provides a stable power supply to its low-voltage components. This tiny NCP177 LDO chip can output up to 500mA output current with a typically low dropout voltage of 200mV at 500mA.

    GPIO and Power Pins

    Given the compact design, the main challenge was to maximize the use of GPIO pins. We tackled this by dividing each of the three available sides of the CodeCell into different I/O sections based on their applications. We also placed power pins along the edges of the module for easy connection to various power sources, allowing you to connect other modules, sensors, and actuators to different sides.

    On the bottom side, 3 out of 5 pins are used for power: a ground pin (GD), a 3.3V logic-level power pin (3V3) and a 5V input charge pin (5V0). This 5V0 pin is connected to the USB input-voltage. This means you can use it to get 5V power when the USB is connected, or you can use it as a power input for charging instead of using the USB.. The other 2 pins are the I2C SDA & SCL pins for adding external digital sensors. If your not using any external and the light/motion sensors, these I2C pins can be set up as GPIOs.

    The other two sides each have a ground pin (GD) and a voltage output pin (VO). Each side also features 3 programmable GPIO pins (IO1, IO2, IO3, IO5, IO6, IO7), which can all be configured as PWM pins (ideal for directly connecting an h-bridge for actuator/motor control). IO1, IO2, and IO3 can also be used as ADC pins.

    The ADC pins support voltages up to 3.3V, and by default, the ADC's voltage reference is set to 2.5V. Please note that this cannot be changed.

    Sensing Capabilities

    The CodeCell's standout features include its onboard sensors. Each unit comes equipped with a built-in light sensor, and there's also an optional motion sensor available to elevate your project's motion detection—especially useful for robotics and wearables!

    • VCNL4040 Light Sensor: This sensor measures both light levels and proximity up to 20 cm. It features a 16-bit high-resolution design that combines a proximity sensor, an ambient light sensor, and a high-power IRED into a compact package. By integrating photodiodes, amplifiers, and an analog-to-digital converter onto a single chip, it provides enhanced functionality. The I2C configuration is directly embedded in the CodeCell library, ensuring the sensor is automatically initialized to optimize its sensing resolution. 
    • Optional 9-axis BNO085 Motion Sensor: This advanced IMU sensor is a pricey upgrade, but we believe it's well worth the investment! It upgrades the CodeCell’s capabilities with an integrated 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer + the BNO085’s advanced sensor fusion algorithms combines the data from these sensors to accurately determine the motion data of the sensor, like: Angular Rotational Reading (Roll, Pitch, Yaw), Motion State (e.g., On Table, Stationary, Motion), Motion Activity (e.g., Driving, Walking, Running), Accelerometer Readings, Gyro Reading, Magnetometer Reading, Gravity Reading, Linear Acceleration Reading, Tap detection, Step Counter. 

    Next we'll dive into how the CodeCell library simplifies both configuring these sensors and reading their data.

    What about the BOOT Pin?

    Some ESP32 development boards include both a RST (Reset) button and a BOOT button to manually put the device into programming mode. However, the ESP32-C3, such as the one on the CodeCell module, can automatically enter boot mode through the serial interface when using the Arduino IDE. This means the CodeCell doesn't need dedicated RST or BOOT buttons, which allowed us to make it as small as it is.

    In the rare case that your CodeCell freezes or encounters an exception (causing it to continuously reset), you can manually force it into boot mode to reflash the firmware. To do this, simply follow these steps:

    • Connect a wire between the SCL pin and the GND pin.
    • Unplug the USB and switch off the battery (if connected).
    • Reconnect the USB port.
    • Reprogram your CodeCell with new code - make sure your code doesn't contain the bug that created the issue.
    • Remove the shorted wire between the SCL pin and the GND pin. Power back your battery on if connected.

    Following these steps will restore your CodeCell back to life.

    How to setup and use your CodeCell?

      To make programming even easier, the CodeCell library provides a wide array of functions for initializing, reading, and managing sensors and power. In this section we're going to explain everything you need to know about setup up your device and it's library.

      Unboxing Your CodeCell

      Let’s start with what you’ll find inside the box. Depending on the options you selected during checkout, in the box you'll find:

      1. CodeCell: The star of the show, your tiny yet mighty board featuring the ESP32-C3 module, programmable GPIO pins, and sensors.
      2. Screws: Four M1.2 x 6mm screws to mount the CodeCell securely in your projects.
      3. Headers: Three sets of female headers which can come unsoldered or soldered, depending on your choice.
      4. Battery/Cable: Depending on your selection during checkout, you’ll either receive a free battery cable for connecting your own battery to the CodeCell's onboard connector or a 170mAh 20C LiPo battery with a pre-soldered cable. This optional battery measures 23 x 17.5 x 8.7 mm and weighing just 4.6 grams. Click here if you like to access the battery's datasheet.

      Powering Up Your CodeCell for the First Time

      Let's start by plugging in a USB-C cable! Once your CodeCell receives power it should: 

      • Initialization: It sets up the internal peripherals and configures the onboard sensors. Once this is being performed it outputs a Hello World message on the Serial Monitor. 
      • Power Check: It monitors the power status, check if the battery is connected and whether it's charging. If no battery is connected for charging, it will run a breathing light animation with the onboard RGB LED. The animation speed changes based on the proximity of the light sensor ~ Bring your hand close to it to slow down.. Move your hand away to speed it back up! The LED flashes blue or green depending on whether the board is powered by USB or battery. If the battery is charging, the LED stays static blue until fully charged.

      Setting Up Your CodeCell

      Next step is to connect the CodeCell to Arduino IDE and run a sketch:

      1. USB Connection: Connect your CodeCell to your PC using a standard USB-C cable. This cable not only powers the board but also allows for reprogramming.
      2. Install the Arduino IDE: If your new to the Arduino-World no worries, just download and install the latest free version of the Arduino IDE software from the official Arduino website. 
      3. Add ESP32 Board Manager URL: If you have never used an ESP32, open the Arduino IDE and navigate to 'File > Preferences'. In the 'Additional Board Manager URLs' field, enter: `https://dl.espressif.com/dl/package_esp32_index.json` and then click ok. Then go to 'Tools > Board > Boards Manager'. Search for 'ESP32' and click 'Install'.
      4. Select the Board: The next step is to select our board. Head to 'Tools > Board' and choose 'ESP32C3 Dev Module'. In a few weeks, you'll be able to search directly for 'CodeCell', but for now, selecting 'ESP32C3 Dev Module' works perfectly fine, since it's the microcontroller used onboard the CodeCell.
      5. Select Port: Go to 'Tools > Port' and select the COM port corresponding to your CodeCell.
      6. Other Settings:  Navigate to 'Tools > USB_CDC_On_Boot' and ensure it's enabled if you plan to use the Serial Monitor. Also, set the clock speed to 160MHz.

      With your IDE all set up, we can now go ahead an install the "CodeCell" library. To do this go to 'Sketch>Include Library>Manage Libraries' - the 'Library Manager' should open up. Just type "CodeCell" and click 'Install' to download the latest version of the CodeCell.

      We are continuously updating and adding new features to this library, so make sure you're using the latest version.

      To quickly get familiar with this library, go to 'File > Examples > CodeCell,' where you'll find multiple examples you can use and modify for your projects. We recommend starting with the 'GettingStarted' example, which contains just a few lines of code but explains all the sensing functionalities available with CodeCell.

      Once you select an example sketch, click the 'Upload' button to flash the code onto your CodeCell. After uploading, open the Serial Monitor 'Tools > Serial Monitor' to see serial data from your CodeCell.

      Here are some additional CodeCell tutorials to help you get started with various applications:

      • Depth Gestures
      • Tap Detection
      • Proximity 
      • Auto Dimming
      • Step Counter
      • Angle Control
      • Personal Activity Guessing
      • Wireless Remote
      • Ai Prompt
      • Alexa Light Control

       CodeCell Library Functions

      To explore the code further, let's break down all the functions and explain what each one does:

      Initializing CodeCell

      The first step in using the CodeCell is to initialize it. This is done using the `myCodeCell.Init()` function, which allows you to specify the sensors you want to enable.

      Available Sensing Macros:

      • LIGHT - Enables Light Sensing.
      • MOTION_ACCELEROMETER - Enables Accelerometer Sensing.
      • MOTION_GYRO - Enables Gyroscope Sensing.
      • MOTION_MAGNETOMETER - Enables Magnetometer Sensing.
      • MOTION_LINEAR_ACC - Enables Linear Acceleration Sensing.
      • MOTION_GRAVITY - Enables Gravity Sensing.
      • MOTION_ROTATION - Enables Rotation Sensing.
      • MOTION_ROTATION_NO_MAG - Enables Rotation Sensing without Magnetometer.
      • MOTION_STEP_COUNTER - Enables Walking Step Counter.
      • MOTION_STATE - Enables Motion State Detection.
      • MOTION_TAP_DETECTOR - Enables Tap Detector.
      • MOTION_ACTIVITY - Enables Motion Activity Recognition.


      You can combine multiple macros using the `+` operator to initialize multiple sensors at once.

      Managing Power

      Call the myCodeCell.Run(frequency) function in the loop() to manage the power status. This function also handles the onboard LED to indicate power status. 

      Run() Function Behavior:

      • This function returns true at the specified frequency, between 10Hz and 100Hz, depending on the value passed, which can be used for time-based operations. E.g. Run(10) returns true every 10Hz, and Run(100) returns true every 100Hz). 
      • The battery and power status are checked every 10Hz. It controls the onboard LED to indicate different power states:
        • Red Blinking (Blinking 10 times) - Battery voltage below 3.3V, entering Sleep Mode until the USB cable is connected for charging.
        • Green LED (Breathing Animation) - Powered by battery
        • Blue LED (Static) - Battery is Charging
        • Green LED (Static) - Battery is fully Charged
        • Blue LED (Breathing Animation) - USB Power

      While charging, the CodeCell will shut down the application, light the static LED blue, and wait until the battery is fully charged. Once fully charged, it will turn static green. Once the cable is disconnected it will start a green breathing-light animation with a speed corresponding to the proximity distance. The animation will shine green when powered by the battery and blue when powered via USB.

      Reading Sensor Data

      After initializing the sensors, you can read their data using various functions provided by the library. Here's a quick rundown of the available functions:

      Light Sensor Functions:

      • Light_ProximityRead() - Reads the proximity value from the light sensor.
      • Light_WhiteRead() - Reads the white light intensity from the light sensor.
      • Light_AmbientRead() - Reads the ambient light intensity from the light sensor.

      Motion Sensor Functions:

      • Motion_AccelerometerRead(float &x, float &y, float &z) - Reads acceleration data along the x, y, and z axes.
      • Motion_GyroRead(float &x, float &y, float &z) - Reads rotational velocity data along the x, y, and z axes.
      • Motion_MagnetometerRead(float &x, float &y, float &z) - Reads magnetic field strength data along the x, y, and z axes.
      • Motion_GravityRead(float &x, float &y, float &z) - Reads gravity vector data along the x, y, and z axes.
      • Motion_LinearAccRead(float &x, float &y, float &z) - Reads linear acceleration data along the x, y, and z axes.
      • Motion_TapRead(uint16_t &x) - Reads the number of taps detected.
      • Motion_StepCounterRead(uint16_t &x) - Reads the number of steps counted.
      • Motion_RotationRead(float &roll, float &pitch, float &yaw) - Reads angular rotational data (roll, pitch, yaw).
      • Motion_RotationNoMagRead(float &roll, float &pitch, float &yaw) - Reads angular rotational data without using the magnetometer.
      • Motion_StateRead(uint16_t &x) - Reads the current state (e.g., On Table, Stationary, Motion).
      • Motion_ActivityRead(uint16_t &x) - Reads the current activity (e.g., Driving, Walking, Running).

      Example Usage:


      Sleep, Power-Saving, Diagnostic & LED Functions

      The CodeCell includes several functions to manage sleep and power-saving modes:

      • WakeUpCheck() - Checks the wake-up reason of the device. If the device wakes up from a timer event, it returns `true`; otherwise, it returns `false`
      • Sleep(uint16_t sleep_sec) - Puts the device into deep sleep mode for a specified duration in seconds. It configures the necessary pins and sensors for low power consumption before entering sleep mode.
      • USBSleep(bool cable_polarity) - Manages the device's sleep mode when the battery level is low or when the device is charging via USB power. It shuts down the application and prepares the device for sleep to allow reprogramming if needed.
      • PrintSensors() - Prints the current readings from all initialized sensors to the serial monitor. This function is especially useful for debugging and data logging.
      • BatteryRead() - This function reads and returns the battery voltage when the USB-C port is disconnected.
      • LED_Breathing(uint32_t rgb_color_24bit) - This function is used in the Run() handler to control the onboard LED & create a breathing effect with a specific color. The `rgb_color_24bit` parameter is a 24-bit color value representing the RGB color. When using this function be careful as the 'Run' function might overwrite your LED color.
      • LED(uint8_t r, uint8_t g, uint8_t b) - This function sets the color of the onboard addressable LED using the RGB model where `r`, `g`, and `b` are 8-bit values representing the red, green, and blue components of the color. Each component ranges from 0 to 255. When using this function be careful as the 'Run' function might overwrite your LED color.

      Congratulations!

      You've now taken your first steps with CodeCell. Dive deeper into the library examples, explore sensor integrations, and start bringing your innovative projects to life with CodeCell!



      Read More

      CoilPad Basics: Your First Steps

      CoilPad Basics: Your First Steps

      The CoilPad is an incredibly thin and innovative actuator that brings motion to your projects in a compact form factor. To understand how it works, let's dive into its unique design and the principles behind its operation.

      In this tutorial we will explain:

      • What is a CoilPad and how does it work?
      • How to control its polarity, position, and speed
      • Making the CoilPad more interactive with the CodeCell sensors

      What is a CoilPad?

      The CoilPad is an actuator made from a flexible planar coil that adheres seamlessly to any smooth surface. By adding a magnet, it transforms into a device capable of magnetic movement, buzzing, or even heating. It’s designed to convert electrical energy into mechanical movement with ease.

      How Does It Work?

      The CoilPad features a flat, ultra-thin coil that interacts with external magnets. When an electric current passes through the coil, it generates a magnetic field that either attracts or repels the magnet, causing movement. By alternating the direction of the current, you can control the motion of the CoilPad. Applying a square wave signal makes the CoilPad oscillate continuously, with adjustable speed and intensity. For smooth organic motions, we will explore the DriveCell PWM library.

      Installing CoilPad

      The CoilPad design makes it easy to install. It comes with a peelable adhesive back, ensuring that it stays firmly attached to any smooth surface. 

      Getting Your CoilPad Moving

      You can start testing it, by pulling one of its pins to 5V and the other to ground, then switch them around. In one instance, the magnet will be repelled, and in the other, it will be attracted. You can connect it to your own transistors or H-bridge module to switch these pins automatically. However, to make it even easier, you can purchase our tiny DriveCell module. The DriveCell is a compact, pin-to-pin compatible H-bridge driver that simplifies the process of controlling actuators like the CoilPad. Its open-source Arduino software library makes actuator control easy, especially for beginners, by providing straightforward software functions and easy-to-follow examples.

      For an in-depth guide on the DriveCell Software Library, check out this article. But here’s a quick recap of how you can use its functions to enhance the CoilPad actuation. Don’t worry, it’s quite simple! Start by downloading the "DriveCell" library from Arduino's Library Manager. Once installed, you’ll be ready to control your device. Before we start, make sure you connect the DriveCell to your microcontroller. We recommend using a CodeCell, which is pin-to-pin compatible, supports all the library functions, and can add wireless control and interactive sensing to your CoilPad.

      1. Init()

      First, we need a basic setup code to get you started:

      #include <DriveCell.h> // This line includes the DriveCell library
      
      DriveCell myCoilPad(IN1, IN2); // Replace IN1 and IN2 with your specific pins
      
      void setup() {
          myCoilPad.Init(); // Initializes your DriveCell connected to a CoilPad
      }
      

      This code gives the name 'myCoilPad' to your DriveCell and tells it to start up and initialize all the necessary peripherals.

      2. Pulse(bool direction, uint8_t ms_duration)

      This function sends a brief burst of power to the CoilPad in a specified polarity. This quick energizing and de-energizing can cause a short, sharp movement of the CoilPad, depending on the polarity.

      myCoilPad.Pulse(1, 10); // Sends a short burst for 10 milliseconds in the specified direction

      3. Buzz(uint16_t us_buzz)

      This function makes the CoilPad vibrate like a buzzer, which is useful for creating audible feedback. 

      myCoilPad.Buzz(100); // Makes the CoilPad buzz with a 100 microsecond pulses
      

      4. Tone()

      The Tone function makes the CoilPad play a tone. This can be used for audible feedback or creative applications where sound is part of the interaction.

      myCoilPad.Tone(); // Plays a tone by varying the frequency
      

      5. Toggle(uint8_t power_percent)

      This function toggles the CoilPad polarity, which can be useful for creating a rapid flapping movement or reversing direction quickly in your code.

      myCoilPad.Toggle(100); // Toggles direction at 100% power

      6. Run(bool smooth, uint8_t power_percent, uint16_t flip_speed_ms)

      This function allows you to continuously flip the polarity of the CoilPad and control its motion speed and smoothness. If smooth is set to true, the actuation will be less sharp and smoothed, which is ideal for slower, controlled movements.

      myCoilPad.Run(true, 50, 1000); // Runs the CoilPad smoothly at 50% power, flipping every 1000 milliseconds

      7. Drive(bool direction, uint8_t power_percent)

      This function lets you control the CoilPad polarity and its magnetic field strength by adjusting the power level.

      myCoilPad.Drive(true, 75); // Moves the CoilPad forward at 75% power
       

      Examples:

      Here's an example where we configure two CoilPads and actuate them at two different speeds:

      #include <DriveCell.h>
      
      #define IN1_pin1 2
      #define IN1_pin2 3
      #define IN2_pin1 5
      #define IN2_pin2 6
      
      DriveCell CoilPad1(IN1_pin1, IN1_pin2);
      DriveCell CoilPad2(IN2_pin1, IN2_pin2);
      
      uint16_t c_counter = 0;
      
      void setup() {
        CoilPad1.Init();
        CoilPad2.Init();
      
        CoilPad1.Tone();
        CoilPad2.Tone();
      }
      
      void loop() {
        delay(1);
        c_counter++;
        if (c_counter < 2000U) {
          CoilPad1.Run(0, 100, 100);
          CoilPad2.Run(0, 100, 100);
        }
        else if (c_counter < 8000U) {
          CoilPad1.Run(1, 100, 1000);
          CoilPad2.Run(1, 100, 1000);
        } else {
          c_counter = 0U;
        }
      }

      Combining with CodeCell Sensors

      To make it even more interactive you can combine the CoilPad and DriveCell with the tiny CodeCell Sensor Module. CodeCell is pin-to-pin compatible with DriveCell, supports all library functions, and can adds wireless control and interactive sensing to your project. This allows you to create more advanced, responsive elements with your CoilPad actuators. 

      With this next example the CodeCell controls two CoilPad that stops flapping when proximity is detected. Their magnetic field gets adjusted dynamically based on how close your hands gets. If no hand is detected it flips the CoilPad polarity every 400 milliseconds.

      #include <CodeCell.h>
      #include <DriveCell.h>
      
      #define IN1_pin1 2
      #define IN1_pin2 3
      #define IN2_pin1 5
      #define IN2_pin2 6
      
      DriveCell CoilPad1(IN1_pin1, IN1_pin2);
      DriveCell CoilPad2(IN2_pin1, IN2_pin2);
      
      CodeCell myCodeCell;
      
      void setup() {
        Serial.begin(115200);
      
       /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */
      
        myCodeCell.Init(LIGHT); /*Initializes Light Sensing*/
      
        CoilPad1.Init();
        CoilPad2.Init();
      
        CoilPad1.Tone();
        CoilPad2.Tone();
      }
      
      void loop() {
        if (myCodeCell.Run()) {
          /*Runs  every 100ms*/
          uint16_t proximity = myCodeCell.Light_ProximityRead();
          Serial.println(proximity);
          if (proximity < 100) {
            CoilPad1.Run(1, 100, 400);
            CoilPad2.Run(1, 100, 400);
          } else {
            proximity = proximity - 100;
            proximity = proximity / 10;
            if (proximity > 100) {
              proximity = 100;
            }
            CoilPad1.Drive(0, (proximity));
            CoilPad2.Drive(0, (proximity));
          }
        }
      }
      

      Feel free to tweak the code with your own creative ideas, or add motion sensing for a new reaction! Get started today with our Arduino libraries! If you have any more question about the CoilPad feel free to email us and we will gladly help out!

      Read More

      FlatFlap Basics: Your First Steps

      FlatFlap Basics: Your First Steps

      The FlatFlap is an incredibly thin and innovative actuator that brings motion to your projects in a compact form factor. To understand how it works, let's dive into its unique design and the principles behind its operation.

      In this tutorial we will explain:

      • What is a FlatFlap and how does it work?
      • How to control its polarity, position and speed
      • Make the FlatFlap more interactive with the CodeCell sensors


      What is a FlatFlap?

      It's Flat and its a Flap ~ the FlatFlap is an actuator made from a flexible PCB (printed circuit board) and aluminum stiffeners, folded together to create a low-force flapping motion. It’s magnetic system converts electrical energy into mechanical movement.

      How Does It Work?

      The FlatFlap features a thin 10mm N52 neodymium magnet on its back, which interacts with the planar copper coil embedded within the flexible PCB. When an electric current passes through the coil, it generates a small magnetic field that either attracts or repels the magnet, causing the flap to move. By alternating the direction of the current, you can control the flapping motion of the actuator. Applying a square wave signal makes the FlatFlap flap continuously, with speeds of up to 25Hz. For smooth organic motions, we will explore the DriveCell PWM  library.

      Installing FlatFlap

      The FlatFlap design makes it easy to install. It comes with a peelable adhesive back and optional M1.2 screws (included) for added security, ensuring that it stays firmly attached to any surface, whether smooth or textured. The adhesive is 3M467, which provides a strong bond but can be removed with tweezers if needed.

      Getting Your FlatFlap Moving

      If you purchased the FlatFlap as a stand-alone actuator, you can start by pulling one of its pins to 5V and the other to ground, then switch them around. In one instance, the flap will be repelled, and in the other, it will be attracted. You can connect it to your own transistors or H-bridge module to switch these pins automatically. However, to make it even easier, you can purchase the FlatFlap directly soldered to our tiny DriveCell module. The DriveCell is a compact, pin-to-pin compatible H-bridge driver that simplifies the process of controlling actuators like the FlatFlap. Its open-source Arduino software library makes actuator control easy, especially for beginners, by providing straightforward software functions and easy-to-follow examples.

      For an in-depth guide on the DriveCell Software Library, check out this article. But here’s a quick recap of how you can use its functions to enhance the FlatFlap actuation. Don’t worry, it’s quite simple! Start by downloading the "DriveCell" library from Arduino's Library Manager. Once installed, you’ll be ready to control your device. Before we start, make sure you connect the DriveCell to your microcontroller. We recommend using a CodeCell, which is pin-to-pin compatible, supports all the library functions, and can add wireless control and interactive sensing to your FlatFlap.

      1. Init()

      First we need a basic setup code to get you started:

      #include <DriveCell.h> // This line includes the DriveCell library
      
      DriveCell myFlatFlap(IN1, IN2); // Replace IN1 and IN2 with your specific pins
      
      void setup() {
          myFlatFlap.Init(); // Initializes your DriveCell connected to a FlatFlap
      }
      

      This code gives the name 'myFlatFlap' to your DriveCell and tells it to start up and initialize all the necessary peripherals.

       2. Pulse(bool direction, uint8_t ms_duration)

      This function sends a brief burst of power to the FlatFlap in a specified polarity. This quick energizing and de-energizing can cause a short, sharp movement of the FlatFlap, depending on the polarity.

      myFlatFlap.Pulse(1, 10); // Sends a short burst for 10 milliseconds in the specified direction

      2. Buzz(uint16_t us_buzz)

      This function makes the FlatFlap vibrate like a buzzer, which is useful for creating audible feedback. 

      myFlatFlap.Buzz(100); // Makes the FlatFlap buzz with a 100 microsecond pulses
      

      3. Tone()

      The Tone function makes the FlatFlap play a tone. This can be used for audible feedback or creative applications where sound is part of the interaction.

      myFlatFlap.Tone(); // Plays a tone by varying the frequency
      

      4. Toggle(uint8_t power_percent)

      This function switches the FlatFlap direction, which can be useful for creating a rapid flapping movement or reversing direction quickly in your code.

      myFlatFlap.Toggle(100); // Toggles direction at 100% power

      5. Run(bool smooth, uint8_t power_percent, uint16_t flip_speed_ms)

      This function allows you to continuously flip the polarity of the FlatFlap and control its motion speed and smoothness. If smooth is set to true, the flapping will be less sharp and smoothed, which is ideal for slower, controlled movements.

      myFlatFlap.Run(true, 50, 1000); // Runs the FlatFlap smoothly at 50% power, flipping every 1000 milliseconds

      6. Drive(bool direction, uint8_t power_percent)

      This function lets you control the FlatFlap polarity and angular position of the flap by adjusting the power level, basically adjusting how strong the magnetic pull or push is.

      myFlatFlap.Drive(true, 75); // Moves the FlatFlap forward at 75% power
       

      Examples:

      Here's an example where we configure two FlatFlaps and flap them at different speeds:

      #include <DriveCell.h>
      
      #define IN1_pin1 2
      #define IN1_pin2 3
      #define IN2_pin1 5
      #define IN2_pin2 6
      
      DriveCell FlatFlap1(IN1_pin1, IN1_pin2);
      DriveCell FlatFlap2(IN2_pin1, IN2_pin2);
      
      uint16_t flap_counter = 0;
      
      void setup() {
        FlatFlap1.Init();
        FlatFlap2.Init();
      
        FlatFlap1.Tone();
        FlatFlap2.Tone();
      }
      
      void loop() {
        delay(1);
        flap_counter++;
        if (flap_counter < 2000U) {
          FlatFlap1.Run(0, 100, 100);
          FlatFlap2.Run(0, 100, 100);
        }
        else if (flap_counter < 8000U) {
          FlatFlap1.Run(1, 100, 1000);
          FlatFlap2.Run(1, 100, 1000);
        } else {
          flap_counter = 0U;
          FlatFlap1.Drive(0, 100);
          FlatFlap2.Drive(1, 100);
          delay(500);
          FlatFlap1.Drive(1, 100);
          FlatFlap2.Drive(1, 100);
          delay(500);
          FlatFlap1.Drive(1, 100);
          FlatFlap2.Drive(0, 100);
          delay(500);
          FlatFlap1.Drive(1, 100);
          FlatFlap2.Drive(1, 100);
          delay(500);
          FlatFlap1.Drive(0, 100);
          FlatFlap2.Drive(0, 100);
          delay(500);
          FlatFlap1.Drive(1, 100);
          FlatFlap2.Drive(1, 100);
          delay(500);
          FlatFlap1.Tone();
          FlatFlap2.Tone();
        }
      }

      Combining with CodeCell Sensors

      To make it even more interactive you can combine the FlatFlap and DriveCell with the tiny CodeCell Sensor Module. CodeCell is pin-to-pin compatible with DriveCell, supports all library functions, and adds wireless control and interactive sensing to your project. This allows you to create more advanced, responsive elements with your FlatFlap actuators. 

      With this next example the CodeCell controls two FlatFlap that stops flapping when proximity is detected. Their angle gets adjusted dynamically based on how close your hands gets.

      #include <CodeCell.h>
      #include <DriveCell.h>
      
      #define IN1_pin1 2
      #define IN1_pin2 3
      #define IN2_pin1 5
      #define IN2_pin2 6
      
      DriveCell FlatFlap1(IN1_pin1, IN1_pin2);
      DriveCell FlatFlap2(IN2_pin1, IN2_pin2);
      
      CodeCell myCodeCell;
      
      void setup() {
        Serial.begin(115200); /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */
      
        myCodeCell.Init(LIGHT); /*Initializes Light Sensing*/
      
        FlatFlap1.Init();
        FlatFlap2.Init();
      
        FlatFlap1.Tone();
        FlatFlap2.Tone();
      }
      
      void loop() {
        if (myCodeCell.Run()) {
          /*Runs  every 100ms*/
          uint16_t proximity = myCodeCell.Light_ProximityRead();
          Serial.println(proximity);
          if (proximity < 100) {
            FlatFlap1.Run(1, 100, 400);
            FlatFlap2.Run(1, 100, 400);
          } else {
            proximity = proximity - 100;
            proximity = proximity / 10;
            if (proximity > 100) {
              proximity = 100;
            }
            FlatFlap1.Drive(0, (proximity));
            FlatFlap2.Drive(0, (proximity));
          }
        }
      }
      

      Feel free to tweak the code with your own creative ideas, or add motion sensing for a new reaction! With FlatFlap, you can bring your creative projects to life with motion in a sleek, compact package. Whether you're adding dynamic elements to art, experimenting with robotics, or developing interactive mechanical displays, the FlatFlap provides a versatile and easy-to-use solution. Get started today with our Arduino libraries! If you have any more question about the FlatFlap feel free to email us and we will gladly help out!

      Read More

      CoilCell Basics: Your First Steps

      CoilCell Basics: Your First Steps

      CoilCell is a compact planar coil designed for various DIY projects. Whether you're just starting or are an experienced maker, CoilCell offers easy integration to simplify your creations. In this tutorial we will explain:

      • What is a CoilCell and how does it work?
      • Getting started with its Arduino software library
      • Program a ball-magnet to bounce every few milliseconds
      • Make the CoilCell more interactive with the CodeCell sensors

      What is CoilCell?
      CoilCell is a thin, planar coil built on a multi-layered PCB, with an integrated driver that simplifies controlling magnetic polarity and strength. It is available in two configurations:

      • 1W CoilCell: 70 turns, with a peak magnetic field of 2.3 mT.
      • 2.5W CoilCell: 200 turns, with a peak magnetic field of 10 mT, which can be upgraded to 17 mT using an iron back-plate.

      Magnetic Applications

      • N52 Magnets: Use lightweight N52 ball or disk magnets for dynamic interactions like bouncing or shaking objects by finding their resonant frequency.
      • FlipDot: Create interactive mechanical pixel by pivoting a magnet to flip. Build your own 3D-printed magnetic FlipDot pixel, and add more for a mini displpay. Both your ears and eyes will love it!
      • Iron Back-Plate: Upgrade the 2.5W CoilCell to boost its peak strength to 17 mT, turning it into a weak electromagnet suitable for attracting small metallic objects like paper clips.
      • Magnetic Dice: Perform fun tricks with our special dice containing a hidden magnet inside, allowing you to create automatic shaking or influencing the roll outcome with the 2.5W CoilCell.

      Safety Tips
      While using the 2.5W 200-Turns CoilCell, it can potentially heating up to 110°C, especially when combined with the iron back-plate. Follow these precautions:

      • Keep hands away from hot surfaces and turn off the coil when not in use.
      • Ensure that 3D-printed parts and materials can withstand high temperatures. 
      • Also, use eye protection when working with small magnets that may be repelled at high speeds.

      How Does CoilCell Work?
      CoilCell utilizes an on-board DRV8837 H-bridge chip to control current flow through the coil, allowing it to switch magnetic polarity:

      • North: IN1 = VCC/PWM, IN2 = GND
      • South: IN1 = GND, IN2 = VCC/PWM
      • Off: IN1 = GND, IN2 = GND

      The DRV8837 chip provides overcurrent protection, undervoltage lockout, and thermal shutdown features, ensuring safe operation.


      Getting Started with CoilCell
      Wiring one of the input-pins to VCC will instantly turn on the CoilCell. But to make it smarter we also developed a Arduino Software Library to make it easier for you to get started.

      You will need to write some basic code to tell CoilCell what to do. Don’t worry, it’s quite simple! Start by downloading the "CoilCell" library from the Arduino's Library Manager. Once this is installed, we are ready to control your device. There are multiple examples that can help you get started but next we will breakdown and understand all the functions:

      Before we start make sure you connect the CoilCell to your microcontroller -- We recommend using a CodeCell which is pin to pin compatible, the same size, supports all the library functions, and can add wireless control + interactive sensing. 

      1. Initialize CoilCell

      #include <CoilCell.h>
      
      CoilCell myCoilCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
      
      void setup() {
          myCoilCell.Init(); // Initializes the CoilCell
      }
      

      This code configures the CoilCell, setting it up for magnetic control based on your selected pins and microcontroller.

      2. Bounce(bool direction, uint8_t ms_duration)

      The Bounce() function makes a magnet bounce up and down. The first parameter, sets the polarity of the CoilCell and the delay_ms, sets the duration for which the magnet is repelled./

      myCoilCell.Bounce(true, 20); //Bounce the magnet up for 20ms

      3. Buzz(uint16_t us_buzz)
      Create a buzzing sound by rapidly alternating the coil’s polarity. Adjust 'us_buzz' to control the frequency of the buzz.

      myCoilCell.Buzz(80); // Generates a buzzing effect at 80 microseconds intervals
      

      4. Tone()
      This function plays a default tone by making the CoilCell vibrate at different saved frequencies.

      myCoilCell.Tone(); // Plays varying tones

      5. Drive(bool direction, uint8_t power_percent)
      By using the CodeCell or any other ESP32 microcontroller, this function lets control the coil’s magnetic polarity and strength. The magnetic strength is adjusted by the 'power_percent', which controls how far the magnet is pushed from the coil.

      myCoilCell.Drive(true, 75); // Drive the coil north with 75% strength
      

      6. Toggle(uint8_t power_percent)
      By using the CodeCell or any other ESP32 microcontroller, this function toggles the coil’s polarity at a set power level, useful for simple magnetic flipping actions.

      myCoilCell.Toggle(60); // Toggle polarity at 60% power

      For other Arduino devices, this command makes the coilcell flip its direction at full power. 

      myCoilCell.Toggle(); // Toggle polarity at 100% power

      7. Vibrate(bool smooth, uint8_t power_percent, uint16_t vib_speed_ms)

      This function flips the coil’s polarity at a specified speed and power. Setting 'smooth' to true creates smoother motions, ideal for slow frequencies below 2 Hz.

      myCoilCell.Vibrate(true, 50, 1000); // Smooth vibration at 50% power every 1000 ms
      

      For other Arduino devices, this command makes the coilcell flip its polarity at full power. 

      myCoilCell.Vibrate(100); // Vibrate at 100% power every 100 ms
      

       

      Here's an example where we initialize a CoilCell to make a 5mm diameter ball magnet bounce. In this example, the CoilCell is initialized with pins 5 and 6. The setup() function calls myCoilCell.Init() to configure the CoilCell. In the loop(), the Bounce() function is used to make the magnet bounce upwards for 20 milliseconds, followed by a 600 milliseconds delay that attracts the magnet back down.

      #include <CoilCell.h>
      
      #define IN1_pin1 5
      #define IN1_pin2 6
      
      CoilCell myCoilCell(IN1_pin1, IN1_pin2);
      
      void setup() {
          myCoilCell.Init(); /*Initialize the CoilCell*/
      }
      
      void loop() {
          myCoilCell.Bounce(0, 20); /*Bounce the magnet up for 20ms*/
          delay(600); /*Attract the magnet back down for 600ms*/
      }
          

      In this next example we use the CodeCell's Motion Sensor to detect tapping. When a new tap is detected the CoilCell flips its magnetic polarity and sets a 1 second delay to flash the onboard LED to yellow.

      #include <CodeCell.h>
      #include <CoilCell.h>
      
      #define IN1_pin1 5
      #define IN1_pin2 6
      
      CoilCell myCoilCell(IN1_pin1, IN1_pin2);
      CodeCell myCodeCell;
      
      void setup() {
        Serial.begin(115200); /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */
      
        myCodeCell.Init(MOTION_TAP_DETECTOR); /*Initializes Tap Detection Sensing*/
        myCoilCell.Init();
        myCoilCell.Tone();
      }
      
      void loop() {
        if (myCodeCell.Run()) {
          /*Runs  every 100ms*/
          if (myCodeCell.Motion_TapRead()) {
            /*If Tap is detected shine the LED Yellow for 1 sec and flip the CoilCell's polarity*/
            myCodeCell.LED(0XA0, 0x60, 0x00U);
            myCoilCell.Toggle(100);
            delay(1000);
          }
        }
      }
      

      With these basic functions, you can start experimenting with CoilCell in your projects. Whether you’re controlling magnets, creating interactive displays, or experimenting with magnetic forces, CoilCell provides a simple and effective solution.

      If you have any more question about the CoilCell feel free to email us and we will gladly help out!

      Read More

      DriveCell Basics: Your First Steps

      DriveCell Basics: Your First Steps

      DriveCell is a tiny but powerful device that helps you easily control motors, actuators, and high-power LED lights for your DIY projects. DriveCell makes controlling these components easy, even if you're new to programming or electronics. 

      In this tutorial we will explain:

      • What is a DriveCell and how does it work?
      • Getting started with its Arduino software library
      • Control two dc-motors and drive them at different speed
      • Make the DriveCell more interactive with the CodeCell sensors

      What is DriveCell?
      Imagine you want to make a small robot and control its motor's speed and direction. This can be complex for beginners and usually would require bulky modules. DriveCell simplifies this process because:

      • It’s a super small driver (just about the size of your fingertip)
      • Can be easily soldered with castellated pins
      • Works with Arduino microcontrollers and has easy to use functions that directly let you control motors, actuators, and LEDs without diving into complicated programming.

      How Does DriveCell Work?
      DriveCell utilizes an on-board DRV8837 H-bridge chip to control current flow through the output pins, controlled by the state of the input pins:

      • Forward Current: IN1 = VCC/PWM, IN2 = GND
      • Reverse Current: IN1 = GND, IN2 = VCC/PWM
      • Off: IN1 = GND, IN2 = GND

      The DRV8837 chip provides overcurrent protection, undervoltage lockout, and thermal shutdown features, ensuring safe operation.

        Getting Started with DriveCell
        Before you can start using DriveCell, you need to set it up and connect it to your project. Here’s a simple guide to get you started:

        • Connecting DriveCell: 
        First, solder the DriveCell output pins to your motor or actuator, and the input and power pins to your microcontroller. Think of these pins like connecting the pieces of a puzzle, allowing the DriveCell to pass current between the output pins.These output pins are controlled by the state of the input pin ~ so pulling IN1 high, will set OUT1 high, and pulling IN2 high, will set OUT2 high. IN1 and IN2 are usually set in opposite polarities to allow current to pass through. These technical details can be all handled by the DriveCell software library.

        • Coding DriveCell: 
        Wiring one of the input-pins to VCC will instantly turn on the DriveCell. But to make it smarter we also developed a Arduino Software Library to make it easier for you to get started. You will need to write some basic code to tell DriveCell what to do. Don’t worry, it’s quite simple! Start by downloading the "DriveCell" library from the Arduino's Library Manager. Once this is installed, we are ready to control your device. There are multiple examples that can help you get started but next we will breakdown and understand all the functions.
        Before we start make sure you connect the DriveCell to your microcontroller. We recommend using a CodeCell which is pin to pin compatible, supports all the library functions, and can add wireless control + interactive sensing. 

         


        1. Init()

        First we need a basic setup code to get you started:

        #include <DriveCell.h> // This line includes the DriveCell library
        
        DriveCell myDriveCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
        
        void setup() {
            myDriveCell.Init(); // Initializes the DriveCell
        }
        

        This code tells the DriveCell to start up and get ready to control your motor or actuator. The Init function makes sure all the necessary peripherals are configured.

        2. Pulse(bool direction, uint8_t ms_duration)

        This command sends a short burst of power in a specified polarity, to quickly energize the actuator and turn it back off. 

        myDriveCell.Pulse(true, 10); // Short burst for 10 milliseconds
        

        3. Buzz(uint16_t us_buzz) 
        This makes the actuator vibrate like a buzzer. It’s great for creating sounds for feedback.

        myDriveCell.Buzz(100); // Creates a 100us buzzing sound

        4. Tone()
        This function plays a default tone by making the actuator vibrate at different saved frequencies.

        myDriveCell.Tone(); // Plays varying tones
        

        5. Toggle(uint8_t power_percent)
        This function simply switches the direction at the full 100% power, which can be useful for reversing the spinning direction of a brushed motor or creating simple flapping movements.

        myDriveCell.Toggle(); // Switches direction

        By using the CodeCell or any other ESP32 microcontroller, you can also adjust the duty cycle 'power_percent'. For magnetic actuators the 'power_percent' controls the magnetic strength, while for brushed motors this adjusts the speed. 

        6. Run(bool smooth, uint8_t power_percent, uint16_t flip_speed_ms)

        By using the CodeCell or any other ESP32 microcontroller, this function lets you flip the polarity of an actuator or reverse a motor every 'flip_speed_ms' at the duty cycle 'power_percent'. Setting 'smooth' to 1, smooths out the motion, which is ideal when driving the FlatFlap or CoilPad with slow motions (less than 2Hz).

        myDriveCell.Run(true, 50, 1000); // Smooth drive at 50% power every 1000 ms

        For other Arduino devices, this command makes the motor/actuator flip its direction (forward and backward) at full speed. For example:

        myDriveCell.Run(500); // Motor changes direction every 500 milliseconds
        

        7. Drive(bool direction, uint8_t power_percent)
        By using the CodeCell or any other ESP32 microcontroller, this function lets you control the speed and direction of your motor. You can make the motor go forward or backward and adjust how fast it goes.

        myDriveCell.Drive(true, 75); // Moves forward at 75% power


        Examples:

        By using any of these functions in a loop, you can create the desired sequence for your motor, actuator, or high-power LEDs. Here's an example where we initialize two dc-motors and drive them at different speeds:

        #include <DriveCell.h>
        
        #define IN1_pin1 2
        #define IN1_pin2 3
        #define IN2_pin1 5
        #define IN2_pin2 6
        
        DriveCell Motor1(IN1_pin1, IN1_pin2);
        DriveCell Motor2(IN2_pin1, IN2_pin2);
        
        uint8_t mode = 0;
        uint8_t speed_percentage = 0;
        
        void setup() {
          Motor1.Init();
          Motor2.Init();
          speed_percentage = 80; /* Set Motor to 80% power */
        }
        
        void loop() {
          delay(3000);
          mode++;
          switch (mode) {
            case 1:
              /* Move forward */
              Motor1.Drive(1, speed_percentage);
              Motor2.Drive(1, speed_percentage);
              break;
            case 2:
              /* Move backward */
              Motor1.Drive(0, speed_percentage);
              Motor2.Drive(0, speed_percentage);
              break;
            case 3:
              /* Turn left */
              Motor1.Drive(1, speed_percentage);
              Motor2.Drive(0, speed_percentage);
              break;
            case 4:
              /* Turn right */
              Motor1.Drive(0, speed_percentage);
              Motor2.Drive(1, speed_percentage);
              break;
            case 5:
              /* Turn off both motors */
              Motor1.Drive(1, 0);
              Motor2.Drive(1, 0);
              if (speed_percentage < 95) {
                speed_percentage += 5; /* Increment speed */
              } else {
                speed_percentage = 50; /* Reset to 50% power */
              }
              mode = 0;
              break;
          }
        }
        

        In this next example we use the CodeCell's Proximity Sensor to activate the motors. This sensor will act as a gesture switch, and activate when a hand is within 5cm away. 

        #include <CodeCell.h>
        #include <DriveCell.h>
        
        #define IN1_pin1 2
        #define IN1_pin2 3
        #define IN2_pin1 5
        #define IN2_pin2 6
        
        CodeCell myCodeCell;
        DriveCell Motor1(IN1_pin1, IN1_pin2);
        DriveCell Motor2(IN2_pin1, IN2_pin2);
        
        uint8_t speed_percentage = 0;
        bool on_flag = 0;
        
        void setup() {
          Serial.begin(115200); /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */
        
          myCodeCell.Init(LIGHT); /*Initializes Light Sensing*/
          Motor1.Init();
          Motor2.Init();
          speed_percentage = 100;
        }
        
        void loop() {
          if (myCodeCell.Run()) {
            /*Runs  every 100ms - Put your code here*/
            if (myCodeCell.Light_ProximityRead() > 3000) {
              /*If Tap is detected shine the LED Yellow for 1 sec*/
              myCodeCell.LED(0XA0, 0x60, 0x00U);
              Motor1.Drive(0, 0);
              Motor2.Drive(0, 0);
              delay(1000);
              on_flag = !on_flag;
            }
            if (on_flag) {
              /*Move forward*/
              Motor1.Drive(1, speed_percentage);
              Motor2.Drive(1, speed_percentage);
            } else {
              Motor1.Drive(0, 0);
              Motor2.Drive(0, 0);
            }
          }
        }
        

        If you have any more question about the DriveCell feel free to email us and we will gladly help out!

        Read More


        Follow

        Github

        • About
        • Software
        • Education
        • Contact
        • FAQs
        • Terms
        • Refund Policy
        • Privacy Policy

        Join our Community ~ Be the first to know about new products and get exciting deals!

        © 2025 Microbots.