Menu
Microbots
0
  • Apprendre
  • Boutique
    • Modules et technologies
    • Maker-Packs
    • Outils et engrenages
    • Robots & Displays
    • Tous les produits
  • Communauté
    • Education
    • Software
  • À propos
    • Notre histoire
    • Tendez la main
    • FAQ
  • français
  • Votre panier est vide
Microbots
  • Apprendre
  • Boutique
    • Modules et technologies
    • Maker-Packs
    • Outils et engrenages
    • Robots & Displays
    • Tous les produits
  • Communauté
    • Education
    • Software
  • À propos
    • Notre histoire
    • Tendez la main
    • FAQ
  • Langue

  • 0 0

CodeCell

Linking Your CodeCell to the MicroLink App

Linking Your CodeCell to the MicroLink App

The MicroLink app simplifies wireless control for your CodeCell – whether you're building tiny robots, setting up DIY sensors, or experimenting with interactive projects. With buttons, sliders, a joystick, and real-time data streaming, you can control, monitor, and debug your projects directly from your phone – no wires, no hassle.

MicroLink App

What is MicroLink?

MicroLink is a Bluetooth mobile app designed to interact with our devices – including the CodeCell. When paired with the MicroLink Arduino library, your CodeCell can:

  • Read input from 4 buttons, 3 sliders, and a joystick
  • Send live sensor data like battery level, proximity, and heading
  • Print messages to the app for debugging or display
  • React in real time to control input

This makes MicroLink ideal for remote control, live feedback, and building interactive electronics.

Installing the Library

Install the CodeCell MicroLink library from the Arduino Library Manager. It includes 6 example sketches covering basic sensor feedback, remote control, and motor interaction. 

How It Works

Here’s a quick overview of how your CodeCell communicates with the app:

Initialization

myMicroLink.Init();

This sets up buttons, sliders, joystick, and Bluetooth notifications for battery, proximity, heading, and messages.

Sending Sensor Data

myMicroLink.ShowSensors(battery, proximity, heading);

Only sends when values change, reducing BLE traffic.

Sending Messages

myMicroLink.Print("Hello from CodeCell");

Use this to send debug or status messages. Print() supports strings up to 20 characters. Combine text and variables like this:

sprintf(message, "%u RPM", MotorRPM);
myMicroLink.Print(message);

Reading Controls

Use these functions to read inputs from the app:

myMicroLink.ReadButtonA();   // true if pressed
myMicroLink.ReadButtonB();
myMicroLink.ReadButtonC();
myMicroLink.ReadButtonD();
myMicroLink.ReadSlider1();   // 0–100
myMicroLink.ReadSlider2();
myMicroLink.ReadSlider3();
myMicroLink.ReadJoystickX(); // joystick X axis
myMicroLink.ReadJoystickY(); // joystick Y axis

Once any of these are used in your code, they automatically appear in the MicroLink app.

Example 1 – Motor Control with Sliders

In this example, two DriveCell modules control motors. Two sliders in the app adjust motor speeds. A button flips polarity:

uint8_t slider1 = myMicroLink.ReadSlider1();
uint8_t slider2 = myMicroLink.ReadSlider2();
DriveCell1.Drive(polarity, slider1);
DriveCell2.Drive(polarity, slider2);

Flip polarity with a button press:

if (myMicroLink.ReadButtonA()) {
    polarity = !polarity;
    myMicroLink.Print("Reversing Polarity");
}

Try It Yourself

Once installed, open the Arduino IDE and go to:

File → Examples → CodeCell MicroLink

You’ll find 6 example sketches ready to explore and customize — no advanced setup needed. Start with the examples, explore the controls, and build something fun!

The MicroLink app is currently in open beta on the Google Play Store and will launch on iOS on May 31st. It’s completely free and features a clean, ad-free interface.


Voir l'article entier

Debugging CodeCell

Debugging CodeCell

CodeCell is designed to be easy to set up and use, but like any microcontroller, issues can arise. This guide will help you troubleshoot and debug CodeCell effectively.

Ensure You Have the Latest Library Versions 

Before troubleshooting, make sure you’re using the latest versions of:

  • CodeCell Library → Always update to the latest version for bug fixes and improvements. 
  • ESP32C3 Board Support Package → Make sure you have the newest ESP32-C3 board definitions installed in the Arduino IDE.

To update:

  1. Open Arduino IDE and navigate to Sketch > Include Library > Manage Libraries.
  2. Search for CodeCell and install the latest version.
  3. Navigate to Tools > Board > Board Manager, search for ESP32, and update to the latest version.

Setting Up and Using CodeCell 

To make programming easier, the CodeCell library provides a variety of functions for initializing, reading, and managing sensors and power. Here’s everything you need to know about setting up your device and its library.

Unboxing Your CodeCell

Inside the box, you’ll find:

  • CodeCell: A tiny yet powerful ESP32-C3-based board with programmable GPIOs and sensors.
  • Screws: Four M1.2 x 6mm screws for mounting.
  • Headers: Three sets of female headers (soldered or unsoldered, based on your selection).
  • Battery/Cable: If purchased, a 170mAh 20C LiPo battery with a pre-soldered cable or a battery connector cable.

Powering Up CodeCell for the First Time

Plug in a USB-C cable, and CodeCell will:

  • Initialize its internal peripherals and sensors. The status is printed on the Serial Monitor and will let you know if there are any issue detected.
  • Check Power Status:
    • If no battery is connected, a breathing LED animation occurs.
    • If powered by USB, the LED flashes blue.
    • If running on battery, the LED flashes green.
    • If charging, the LED remains static blue until fully charged.

Common Power Issues & Fixes:

  • Serial Not working?
    • Check if your USB-C cable supports both power and data.
    • Ensure Tools/USB_CDC_On_Boot is enabled
    • Try a different USB port or power adapter.
  • Battery not detected?
    • Ensure the battery is properly connected and charged.

Connecting CodeCell to the Arduino IDE

Step 1: Install Arduino IDE

Download the latest version from the official Arduino website.

Step 2: Add ESP32 Board Support

  1. Open Arduino IDE and go to File > Preferences.
  2. In the 'Additional Board Manager URLs' field, enter:
    https://dl.espressif.com/dl/package_esp32_index.json
    
  3. Click OK and restart Arduino IDE.

Step 3: Select the Correct Board and Port

  1. Navigate to Tools > Board > ESP32C3 Dev Module.
  2. Select the correct COM Port under Tools > Port.
  3. Enable USB_CDC_On_Boot in Tools > USB_CDC_On_Boot.
  4. Set the CPU clock speed to 160MHz.

Step 4: Install the CodeCell Library

  1. Navigate to Sketch > Include Library > Manage Libraries.
  2. Search for CodeCell and install the latest version.
  3. Open File > Examples > CodeCell, and try the GettingStarted example.

Step 5: Upload & Run Your First Sketch

  1. Click the Upload button.
  2. Open Tools > Serial Monitor to see output from your CodeCell.

CodeCell Library & Functions

Initializing CodeCell

The first step is to initialize the CodeCell using:

myCodeCell.Init(SENSOR_MACRO);

Available Macros:

  • LIGHT → Enables Light Sensing.
  • MOTION_ACCELEROMETER → Enables Accelerometer Sensing.
  • MOTION_GYRO → Enables Gyroscope Sensing.
  • MOTION_MAGNETOMETER → Enables Magnetometer Sensing.
  • MOTION_STEP_COUNTER → Enables Step Counting.
  • MOTION_ACTIVITY → Detects Walking, Running, or Driving.

You can combine multiple macros using the + operator:

myCodeCell.Init(LIGHT + MOTION_ACCELEROMETER + MOTION_GYRO);

More Detailed Debugging 

  • CodeCell Not Detected in Arduino IDE
    • Ensure the USB-C cable supports data transfer, not just power.
    • Restart Arduino IDE and try selecting the correct COM port.
    • Check Device Manager (Windows) / System Report (Mac) to verify if CodeCell appears as a USB device.
  • Code Upload Fails
    • Make sure USB_CDC_On_Boot is enabled.
    • If CodeCell is stuck in a reset loop:
      • Short SCL (GPIO9) to GND.
      • Unplug USB and turn off battery.
      • Plug USB back in and re-upload the sketch.
      • Remove the short once reprogrammed.
  • Serial Monitor Not Showing Data
    • Ensure baud rate is set to 115200.
    • Go to Tools > USB_CDC_On_Boot and enable it.
    • Ensure the USB-C cable supports data transfer, not just power.
    • Try restarting the Serial Monitor.
  • Unexpected LED Behavior
    • 🔴 Flashing Red → Low battery (<3.3V), entering sleep mode.
    • 🔵 Static Blue → Battery charging.
    • 🟢 Breathing Green → Running on battery.
    • 🔵 Breathing Blue → Fully charged.
  • Sensors Not Responding
    •  Ensure you've initialized the correct sensor using myCodeCell.Init(SENSOR_MACRO);
    • Check the Serial Monitor this should help you identify why the sensor is not responding
    • If using external sensors avoid using I2C addresses 0x60 (VCNL4040) and 0x4A (BNO085) as there will be conflicts

Final Thoughts

Hope this has helped you identify the root cause. If you're still facing the issue, don’t hesitate to reach out - we’d be glad to help!

Voir l'article entier

CodeCell: Connecting with BLE

CodeCell: Connecting with BLE

Bluetooth Low Energy (BLE) is a powerful way to communicate wirelessly between your CodeCell and other devices like smartphones, tablets, and even other microcontrollers. In this guide, we’ll set up BLE on CodeCell, allow it to receive commands from a BLE client, and control its RGB LED based on the received data.

What is BLE? 

BLE is an energy-efficient version of Bluetooth that allows devices to exchange small amounts of data with low power consumption. Here are it's key concepts:

  • BLE Server → CodeCell acts as a server, advertising itself to other devices.
  • BLE Client → A phone, tablet, or another microcontroller that connects to CodeCell.
  • BLE Service → A collection of characteristics that define the data being sent.
  • BLE Characteristic → A specific data point (e.g., button presses, sensor readings).

Viewing BLE Data on a Smartphone

Before we start testing, your need to download an app to send BLE data on your  smartphone. So start by downloading a BLE scanner app:

  • Android → nRF Connect or "BLE Scanner"
  • iOS → nRF Connect

Setting Up BLE on CodeCell

To make CodeCell advertise itself as a BLE device, we need to initialize BLE, create a service and characteristic, and start advertising.

This code creates a BLE server, advertises a service, and sets up a characteristic that can be read and written by a connected device. The CodeCell will receive the button characteristic and control its onboard RGB LED:

  • If the button value is 1, the LED turns red.
  • If the button value is 0, the LED turns green.
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

#include <CodeCell.h>
CodeCell myCodeCell;

BLECharacteristic *pButtonCharacteristic = NULL;
#define BUTTON_UUID "abcd1234-abcd-1234-abcd-123456789012"

class MyServerCallbacks : public BLEServerCallbacks {
  void onConnect(BLEServer *pServer) override {
    Serial.println("BLE Connected");
    delay(1000);
  }

  void onDisconnect(BLEServer *pServer) override {
    Serial.println("BLE Disconnected");
    delay(500);
    BLEDevice::startAdvertising(); // Restart advertising
  }
};

// Callback class for handling button writes
class ButtonCallback : public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pCharacteristic) override {
   String value = pCharacteristic->getValue();
    
    if (value.length() > 0) {
      int buttonState = value[0]; 

      Serial.print("Button State: ");
      Serial.println(buttonState);

      if (buttonState == 1) {
        myCodeCell.LED(255, 0, 0); // Red LED when button is 1
      } else {
        myCodeCell.LED(0, 255, 0); // Green LED when button is not 1
      }
    }
  }
};

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(LIGHT); // Initializes the light sensor

    BLEDevice::init("CodeCell_BLE"); // Set BLE device name
    BLEServer *bleServer = BLEDevice::createServer();
    bleServer->setCallbacks(new MyServerCallbacks());

    BLEService *bleService = bleServer->createService(BLEUUID("12345678-1234-5678-1234-56789abcdef0"));

    // Create BLE characteristic for button state
    pButtonCharacteristic = bleService->createCharacteristic(
        BUTTON_UUID,
        BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
    );
    pButtonCharacteristic->addDescriptor(new BLE2902());
    pButtonCharacteristic->setCallbacks(new ButtonCallback());

    bleService->start();

    BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
    pAdvertising->addServiceUUID("12345678-1234-5678-1234-56789abcdef0");
    BLEDevice::startAdvertising();
}

void loop() {
    // No need to continuously check, LED updates only on BLE write
}

How This Code Works

  • BLE Initialization → CodeCell advertises itself as a BLE device called "CodeCell_BLE".
  • BLE Service & Characteristic → A service with a button characteristic is created.
  • BLE Callbacks → The server prints "BLE Connected" when a client connects and "BLE Disconnected" when it disconnects.
  • Advertising Restart → When disconnected, BLE automatically starts advertising again so new devices can connect.

Testing the LED Control  

  • Connect to "CodeCell_BLE" in the BLE Scanner app.
  • Select the service you created - typically displayed as Unknown Service
  • Find the button characteristic (BUTTON_UUID) and send the value:
    • Write 1 → LED turns red 🔴
    • Write 0 → LED turns green 🟢

Sending Sensor Data

Next we'll define a new BLE characteristic that allows CodeCell to send sensor values to a connected device.

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

#include <CodeCell.h>
CodeCell myCodeCell;

BLECharacteristic *pSensorCharacteristic = NULL;
#define SENSOR_UUID "abcd5678-abcd-5678-abcd-56789abcdef0"

class MyServerCallbacks : public BLEServerCallbacks {
  void onConnect(BLEServer *pServer) override {
    Serial.println("BLE Connected");
    delay(1000);
  }

  void onDisconnect(BLEServer *pServer) override {
    Serial.println("BLE Disconnected");
    delay(500);
    BLEDevice::startAdvertising(); // Restart advertising
  }
};

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(LIGHT); // Initialize light and proximity sensor

    BLEDevice::init("CodeCell_BLE"); // Name the BLE device
    BLEServer *bleServer = BLEDevice::createServer();
    bleServer->setCallbacks(new MyServerCallbacks());

    BLEService *bleService = bleServer->createService(BLEUUID("12345678-1234-5678-1234-56789abcdef0"));

    // Create BLE characteristic for sensor data
    pSensorCharacteristic = bleService->createCharacteristic(
        SENSOR_UUID,
        BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY
    );
    pSensorCharacteristic->addDescriptor(new BLE2902());

    bleService->start();

    BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
    pAdvertising->addServiceUUID("12345678-1234-5678-1234-56789abcdef0");
    BLEDevice::startAdvertising();
}

void loop() {
    if (myCodeCell.Run(10)) { // Read every 100ms (10Hz)
        uint16_t proximity = myCodeCell.Light_ProximityRead();
        Serial.print("Proximity: ");
        Serial.println(proximity);

        // Convert proximity value to string and send over BLE
        String proximityStr = String(proximity);
        pSensorCharacteristic->setValue(proximityStr.c_str());
        pSensorCharacteristic->notify(); // Notify connected device
    }
}

How it works?

  • This code sets up a new characteristic (SENSOR_UUID) that clients can read and get real-time updates:
    • PROPERTY_READ → Allows the client to read the value manually.
    • PROPERTY_NOTIFY → Automatically sends updates when new data is available.
  • The Light_ProximityRead() function gets a value from the onboard light sensor that detects nearby objects. We convert the number to a string and send it to the BLE client.

Try it out

Now that CodeCell is sending proximity sensor data over BLE, you can view it on a phone.

  • Open a BLE app like nRF Connect (Android/iOS)
  • Scan for "CodeCell_BLE" and connect
  • Find the sensor characteristic (SENSOR_UUID)
  • Enable notifications and watch the proximity data update in real-time!
  • Your Serial Monitor data should match the data sent to your phone

Move an object near the sensor and see how values change!

What’s Next?

Now that you can control CodeCell via BLE, try:

  • Adding more commands (e.g., blue LED, blinking, sensor triggers)
  • Receiving multiple values (e.g., send accelerometer or proximity sensor data)
  • Building a full BLE-controlled IoT device or even connect it with an other app


 

Voir l'article entier

CodeCell: Getting Started with Wi-Fi

CodeCell: Getting Started with Wi-Fi

The CodeCell module, powered by the ESP32-C3, has built-in Wi-Fi capabilities that allow it to connect to the internet, communicate with other devices, and even host a small web server. Whether you're a beginner or an experienced maker, this guide will help you get started with Wi-Fi on CodeCell.

What is Wi-Fi, and Why Use It?

Wi-Fi allows your CodeCell to wirelessly connect to the internet or a local network. This means you can:

  • Control your CodeCell remotely from a smartphone or computer
  • Send and receive data over the internet
  • Host a small web page that other devices can access

Now, let's go step by step to connect CodeCell to Wi-Fi.

Connecting CodeCell to a Wi-Fi Network

To connect your CodeCell to a Wi-Fi network, you need to provide the network name (SSID) and password. Let's use the Arduino IDE to write a simple program that connects CodeCell to Wi-Fi.

#include <WiFi.h>
#include <CodeCell.h>

CodeCell myCodeCell;
const char* ssid = "your_SSID"; // Replace with your Wi-Fi name
const char* password = "your_PASSWORD"; // Replace with your Wi-Fi password

void setup() {
    Serial.begin(115200); // Start the Serial Monitor
    myCodeCell.Init(LIGHT); // Set up CodeCell's light sensor
    WiFi.begin(ssid, password); // Connect to Wi-Fi

    Serial.print("Connecting to Wi-Fi");
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print("."); // Print dots while connecting
    }
    
    Serial.println("\nConnected!");
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP()); // Print the assigned IP address
}

void loop() {
    // Run every 10Hz
    if (myCodeCell.Run(10)) {
        // Your main loop code here
    }
}

How It Works:

  • This code starts the Serial Monitor to track the Wi-Fi connection progress.
  • It connects to Wi-Fi using WiFi.begin(ssid, password);.
  • Once connected, it prints the assigned IP address.

Troubleshooting:

  • If it doesn’t connect, double-check your SSID and password.
  • Make sure your router is on and not blocking unknown devices.

Hosting a Simple Web Page on CodeCell

Once CodeCell is connected to Wi-Fi, we can make it act like a tiny web server! This means we can control it or display information using a web page.

#include <WiFi.h>
#include <WebServer.h>
#include <CodeCell.h>

CodeCell myCodeCell;
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

WebServer server(80);

void handleRoot() {
    int proximityValue = myCodeCell.Light_ProximityRead(); // Read proximity sensor
    String response = "

Welcome to CodeCell Wi-Fi Server!

"; response += "

Proximity Value: " + String(proximityValue) + "

"; server.send(200, "text/html", response); } void setup() { Serial.begin(115200); myCodeCell.Init(LIGHT); // Set up CodeCell's light sensor WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to Wi-Fi"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); } void loop() { if(myCodeCell.Run(10)){ server.handleClient(); } }

How It Works:

  • This code sets up a simple web server that displays a message.
  • When you type the IP address (printed in Serial Monitor) into a browser, it will show a webpage saying "Welcome to CodeCell Wi-Fi Server!" and shows the current proximity value read by the CodeCell.

Try It Out!

  1. Upload the code to CodeCell.
  2. Open the Serial Monitor to find the IP Address.
  3. Type the IP address into a browser – you should see the message!
  4. Refresh the page to see the proximity value update

Sending Data to a Server (Basic IoT Example)

CodeCell can also send data to a web server, such as a cloud service that collects sensor readings.

#include <WiFi.h>
#include <HTTPClient.h>
#include <CodeCell.h>

CodeCell myCodeCell;
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* serverName = "http://example.com/data"; // Replace with your server URL

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(LIGHT); // Set up CodeCell's light sensor
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("Connected to Wi-Fi");
}

void loop() {
    if (myCodeCell.Run(10)) { // Run every 10hz
        HTTPClient http;
        http.begin(serverName);
        int httpResponseCode = http.GET();
        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);
        http.end();
    }
}

How It Works:

  • The CodeCell connects to Wi-Fi and sends a request to http://example.com/data.
  • The response is printed in the Serial Monitor.
  • You can use this method to send sensor data to a web service!

 

Conclusion

Wi-Fi makes CodeCell powerful for IoT projects! Start experimenting, and soon you’ll be building amazing projects!

Voir l'article entier

CodeCell: Using the Magnetometer to Build a Digital Compass

CodeCell: Using the Magnetometer to Build a Digital Compass

Ever wondered how your phone knows which direction you’re facing? It’s all thanks to a magnetometer! Your CodeCell comes with a BNO085 3-axis magnetometer, which detects magnetic fields in three directions. This allows you to measure heading (direction), detect magnetic interference, and even create a simple digital compass! 

What is a Magnetometer?

A magnetometer measures the Earth's magnetic field along three axes:

  • X-axis → Measures left-right magnetic field strength.
  • Y-axis → Measures forward-backward magnetic field strength.
  • Z-axis → Measures up-down magnetic field strength.

By using these values, we can calculate the compass heading (0° to 360°) and determine which direction CodeCell is pointing.

Step 1: Read Magnetometer Data from CodeCell

Let’s start by initializing the magnetometer and reading raw magnetic field values.

#include <CodeCell.h>

CodeCell myCodeCell;

float x = 0.0;  // Magnetic field on X-axis
float y = 0.0;  // Magnetic field on Y-axis
float z = 0.0;  // Magnetic field on Z-axis

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_MAGNETOMETER); // Initialize the magnetometer
}

void loop() {
  if (myCodeCell.Run(10)) { // Read at 10Hz (every 100ms)
    myCodeCell.Motion_MagnetometerRead(x, y, z); // Get magnetometer readings

    Serial.print("Mag X: "); Serial.print(x);
    Serial.print("  Y: "); Serial.print(y);
    Serial.print("  Z: "); Serial.println(z);
  }
}

Once you upload the code and open the Serial Monitor, you’ll see values like:

Mag X: 12.4  Y: -7.8  Z: 35.2

What Do These Values Mean?

  • If you rotate CodeCell, X and Y values will change based on direction.
  • If you tilt CodeCell, the Z value will change.
  • If you place CodeCell near a magnet, all values will fluctuate dramatically.

Step 2: Convert Magnetometer Data into a Compass Heading

To build a digital compass, we need to convert X and Y values into an angle using the atan2() function.

#include <CodeCell.h>
#include <math.h>  // Needed for atan2 function

CodeCell myCodeCell;

float x = 0.0, y = 0.0, z = 0.0;

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(MOTION_MAGNETOMETER);  // Initialize the magnetometer
}

void loop() {
    if (myCodeCell.Run(10)) { // Read at 10Hz
        myCodeCell.Motion_MagnetometerRead(x, y, z); // Read magnetometer values

        // Calculate heading (angle in degrees)
        float heading = atan2(y, x) * (180.0 / M_PI);
        
        // Ensure heading is in the range 0° - 360°
        if (heading < 0) {
            heading += 360;
        }

        Serial.print("Compass Heading: ");
        Serial.println(heading); // Print heading in degrees
    }
}

The heading value (0° to 360°) tells us which direction CodeCell is pointing:

Heading (°) Direction
0° (or 360°) North ↑
90° East →
180° South ↓
270° West ←

Try rotating CodeCell and watch the heading change!

Step 3: Show Direction with the Onboard LED

We can now light up the LED in different colors based on direction:

  • 🔵 North (0° - 45° & 315° - 360°) → Blue LED
  • 🟢 East (45° - 135°) → Green LED
  • 🔴 South (135° - 225°) → Red LED
  • 🟡 West (225° - 315°) → Yellow LED
#include <CodeCell.h>
#include <math.h>

CodeCell myCodeCell;

float x = 0.0, y = 0.0, z = 0.0;

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(MOTION_MAGNETOMETER);  // Initialize the magnetometer
}

void loop() {
    if (myCodeCell.Run(10)) { // Read at 10Hz
        myCodeCell.Motion_MagnetometerRead(x, y, z); // Read magnetometer values

        // Calculate heading
        float heading = atan2(y, x) * (180.0 / M_PI);
        if (heading < 0) heading += 360;

        Serial.print("Heading: ");
        Serial.println(heading);

        // Change LED color based on heading
        if (heading >= 315 || heading < 45) {
            myCodeCell.LED(0, 0, 255); // Blue for North
        } else if (heading >= 45 && heading < 135) {
            myCodeCell.LED(0, 255, 0); // Green for East
        } else if (heading >= 135 && heading < 225) {
            myCodeCell.LED(255, 0, 0); // Red for South
        } else {
            myCodeCell.LED(255, 255, 0); // Yellow for West
        }
    }
}

Experiment with Your Own Ideas!

Now that you can read magnetometer data and calculate direction, try:

  • Displaying the direction (N, E, S, W) on an OLED screen.
  • Detecting magnetic field when near coils or magnets.
  • Combining with other sensors

 

Voir l'article entier

CodeCell: Reading the Gyroscope

CodeCell: Reading the Gyroscope

The CodeCell comes with a built-in BNO085 3-axis gyroscope, which can measure angular velocity - how fast CodeCell is rotating around each axis - making it easier to detect directional changes.

What is a Gyroscope?

Unlike an accelerometer that measures movement in a straight line, a gyroscope detects rotational motion. It tells you how fast CodeCell is spinning in degrees per second (°/s).

  • X-axis → Rotation around the left-right axis (pitch)
  • Y-axis → Rotation around the front-back axis (roll)
  • Z-axis → Rotation around the top-bottom axis (yaw)

 

Step 1: Read Gyroscope Data from CodeCell

Before we can use the gyroscope, we need to initialize it and start reading data.

This code reads the X, Y, and Z angular velocity values and prints them every 100ms.

#include <CodeCell.h>

CodeCell myCodeCell;

float x = 0.0;  // Angular velocity around X-axis
float y = 0.0;  // Angular velocity around Y-axis
float z = 0.0;  // Angular velocity around Z-axis

void setup() {
  Serial.begin(115200); 
  myCodeCell.Init(MOTION_GYRO); // Initialize the gyroscope
}

void loop() {
  if (myCodeCell.Run(10)) { // Read at 10Hz (every 100ms)
    myCodeCell.Motion_GyroRead(x, y, z); // Get gyro readings

    Serial.print("Gyro X: "); Serial.print(x);
    Serial.print("  Y: "); Serial.print(y);
    Serial.print("  Z: "); Serial.println(z);
  }
}

What You'll Notice:

  • When CodeCell is still, all values should be close to 0.
  • If you tilt it forward or backward, X-axis values change.
  • If you twist it left or right, Y-axis values change.
  • If you rotate it like a steering wheel, Z-axis values change.

The higher the value, the faster the rotation.

Step 2: Detect Rotation & Change LED Color

Now, let's detect when CodeCell rotates left or right and change the RGB LED color accordingly.

This program:

  • Turns the LED green when rotated to the right (positive Z).
  • Turns the LED red when rotated to the left (negative Z).
#include <CodeCell.h>

CodeCell myCodeCell;

float x = 0.0, y = 0.0, z = 0.0;
const float ROTATION_THRESHOLD = 3.0; // Rotation speed threshold (°/s)

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(MOTION_GYRO);  // Initialize gyroscope
}

void loop() {
    if (myCodeCell.Run(10)) { // Read at 10Hz
        myCodeCell.Motion_GyroRead(x, y, z); // Get gyroscope values

        Serial.print("Gyro Z: ");
        Serial.println(z); // Print rotation speed

        if (z > ROTATION_THRESHOLD) { 
            myCodeCell.LED(0, 255, 0); // Turn LED green(rotating right)
        } 
        else if (z < -ROTATION_THRESHOLD) {
            myCodeCell.LED(255, 0, 0); // Turn LED red (rotating left)
        } 
        else {
            myCodeCell.LED(0, 0, 0); // Turn LED off when not rotating
        }
    }
}

The gyroscope measures angular velocity in degrees per second (°/s). If the value of Z rotation (yaw) exceeds the threshold, we assume CodeCell is being rotated.

  • Z > 3 → Rotating right, LED turns green.
  • Z < -3 → Rotating left, LED turns red.

Try changing ROTATION_THRESHOLD to increase or decrease the sensitivity.

  • Higher value = Detects only fast rotations
  • Lower value = Detects even small rotations

Experiment with Your Own Ideas!

Now that you can track rotation, try:

  • Using different LED colors for different axes
  • Detecting quick flicks or gestures
  • Learn and Tracking rotation over time 

 

Voir l'article entier

CodeCell: Reading Acceleration & Shaking  Detection

CodeCell: Reading Acceleration & Shaking Detection

Inside your CodeCell is a BNO085 3-axis accelerometer, a tiny sensor that measures movement. With just a few lines of code, you can detect shaking and even trigger an LED light when movement is detected! Let's break it down step by step.

What is an Accelerometer?

An accelerometer measures acceleration - how fast something is speeding up or slowing down. It detects:

  • Left & Right (X-axis)
  • Forward & Backward (Y-axis)
  • Up & Down (Z-axis)

It even feels gravity! When CodeCell is still, the Z-axis will show a value close to 9.81 m/s², which is Earth's gravity.

Step 1: Read Motion from CodeCell

First, let's start by reading real-time movement values from CodeCell's onboard accelerometer. This code will show how much CodeCell is moving in each direction:

#include <CodeCell.h>

CodeCell myCodeCell;

float x = 0.0;  // X-axis acceleration
float y = 0.0;  // Y-axis acceleration
float z = 0.0;  // Z-axis acceleration

void setup() {
  Serial.begin(115200); 
  myCodeCell.Init(MOTION_ACCELEROMETER); // Initialize the accelerometer
}

void loop() {
  if (myCodeCell.Run(10)) {  // Run at 10 times per second (10Hz)
    myCodeCell.Motion_AccelerometerRead(x, y, z); // Read motion values
    Serial.print("X: "); Serial.print(x);
    Serial.print("  Y: "); Serial.print(y);
    Serial.print("  Z: "); Serial.println(z);
  }
}

What You’ll Notice:

  • When CodeCell is still, facing up, X and Y should be close to 0, and Z should be around 9.81 (gravity).
  • When you move CodeCell left or right, X changes.
  • When you move it forward or backward, Y changes.
  • When you shake it, all values jump around!

Step 2: Detect a Shaking 

Now, let’s detect when CodeCell is shaken and use the onboard RGB LED to signal it.

This program will turn the LED red if a shake is detected.

#include <CodeCell.h>
#include <math.h>  // Needed for square root calculations

CodeCell myCodeCell;

float x = 0.0, y = 0.0, z = 0.0;
const float SHAKE_THRESHOLD = 15.0;  // Adjust this value for sensitivity

void setup() {
    Serial.begin(115200);
    myCodeCell.Init(MOTION_ACCELEROMETER);  // Initialize accelerometer
}

void loop() {
    if (myCodeCell.Run(10)) { // Check every 100ms (10Hz)
        myCodeCell.Motion_AccelerometerRead(x, y, z); // Read accelerometer data

        // Calculate total movement strength (vector magnitude)
        float totalAcceleration = sqrt(x * x + y * y + z * z);

        Serial.print("Total Acceleration: ");
        Serial.println(totalAcceleration); // Show acceleration strength

        // If the acceleration is stronger than the threshold, it's a shake!
        if (totalAcceleration > SHAKE_THRESHOLD) {
            Serial.println("Shake detected!");
            myCodeCell.LED(255, 0, 0); // Turn LED red
            delay(500); // Keep LED on for 0.5 seconds
        } else {
            //Not shaking
        }
    }
}

Instead of checking X, Y, and Z separately, we combine them into a single value:

This tells us how much CodeCell is moving overall, no matter the direction. If totalAcceleration jumps above 15.0, we assume CodeCell is being shaken. The onboard RGB LED turns red for 0.5 seconds to signal the shake.

Experiment with Your Own Ideas!

Now that you can detect movement, here are some fun challenges:

  • Change LED colors based on movement (e.g., blue for tilting, red for shaking).
  • Use the accelerometer to detect taps or knocks.
  • Learn how CodeCell moves when attached to a robot or vehicle!

By understanding motion sensing, you're learning the same technology used in smartphones, drones, and rockets! 🚀


Voir l'article entier

CodeCell: Controlling the Onboard RGB LED

CodeCell: Controlling the Onboard RGB LED

The onboard RGB LED on CodeCell can also be controlled programmatically to display different colors based on your project's needs.

With CodeCell’s built-in function, you can set the LED color easily:

myCodeCell.LED(uint8_t r, uint8_t g, uint8_t b); 
  • r → Red component (0-255)
  • g → Green component (0-255)
  • b → Blue component (0-255)

This allows full RGB color control for your project's needs.

Adjusting LED Brightness

In addition to color control, you can also adjust the brightness of the onboard LED using the following function:

myCodeCell.LED_SetBrightness(uint16_t level); 
  • level → Brightness level from 0 (off) to 10 (maximum brightness)

By default, the brightness level is set to 7.

For example, to turn off the LED completely during normal operation, use:

myCodeCell.LED_SetBrightness(0); // Turn off CodeCell LED 

Note: Even with the brightness set to 0, the LED will still blink red when the battery is low, ensuring you don’t miss important power status alerts.

Example: Changing the LED Based on Proximity

In this example, the onboard RGB LED turns red when an object is detected within a certain range using the light sensor’s proximity detection.

#include <CodeCell.h>

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, including proximity
}

void loop() {
    if (myCodeCell.Run(10)) {
        // Runs every 100ms to check proximity
        uint16_t proximity = myCodeCell.Light_ProximityRead();
        
        // Check if an object is within range
        if (proximity > 100) {
            myCodeCell.LED(0xFF, 0, 0); // Set LED to Red when proximity is detected
            delay(1000); // Keep the LED on for 1 second
        } else {
            // No action if the object is out of range
        }
    }
}

Notes About the onboard LED

Remember that the onboard RGB LED is also used for battery and power status indication. When using myCodeCell.Run(), the LED may be overridden to reflect charging or battery conditions.

If you want to control the LED without interruptions, you may need to adjust how often myCodeCell.Run() is called or ensure your LED commands are applied after system updates.

Additionally, adjusting the brightness level can help manage the visibility of the LED in different environments, or turn it off completely during operation while still maintaining critical low-battery alerts.


Voir l'article entier

CodeCell: I2C Communication

CodeCell: I2C Communication

I2C is a widely used protocol for communicating with sensors, displays, and other peripherals. CodeCell simplifies I2C communication by automatically configuring the I2C bus at initialization, so you can start using it right away.

I2C Pin Configuration

The I2C's SDA and SCL pins are located on the lower side of the CodeCell board.

  • SDA (Data Line) → GPIO8
  • SCL (Clock Line) → GPIO9
  • Speed → 400kHz (Fast Mode I2C)

CodeCell automatically configures I2C in the Init() function, and this configuration cannot be changed if you plan to use the onboard light and motion sensors, as they are connected to the same I2C bus.

The following onboard sensors are already using I2C, so make sure not to use the same addresses when connecting other I2C devices like displays, additional sensors, or modules:

Sensor Address
VCNL4040 (Light Sensor) 0x60
BNO085 (IMU - Motion Sensor) 0x4A

 

Note: If a new I2C device has the same address as one of these onboard sensors, they will conflict, and you may get incorrect or no data.

Built-in I2C Pull-up Resistors

To ensure stable I2C communication, CodeCell has 2kΩ pull-up resistors already connected to the SDA and SCL lines. This means you don’t need to add external pull-ups when using external I2C sensors.

Reading Data from an I2C Device

To communicate with an external I2C device, use the standard 'Wire.h' library.

Unlike standard Arduino I2C devices, CodeCell has multiple onboard sensors on the same I2C bus. Calling Wire.endTransmission(false); ensures the bus stays active, allowing the onboard sensors to function properly.

Example: 

Wire.beginTransmission(SLAVE_ADDRESS);  // Start communication with the device
Wire.write(SLAVE_REG);                 // Send the register we want to read
Wire.endTransmission(false);            // Don't release the bus (needed for onboard sensors)
Wire.requestFrom(SLAVE_ADDRESS, 1);     // Request 1 byte from the slave

if (Wire.available()) {
    uint8_t data = Wire.read();         // Read received byte
    Serial.println(data);
}

Conclusion

CodeCell automatically configures the I2C bus, so no need to manually set it up. It also automatically configures the onboard sensors, while also supporting additional I2C devices!

Voir l'article entier

CodeCell: Read Analog Values with ADC

CodeCell: Read Analog Values with ADC

Analog sensors, potentiometers, and other variable inputs require an Analog-to-Digital Converter (ADC) to be read by a microcontroller. With CodeCell, reading an analog signal is as simple as calling pinADC().

How to Use pinADC()

To read an analog value, use:

uint16_t myADC = myCodeCell.pinADC(uint8_t pin_num);
  • pin_num → The ADC pin you want to read from (IO1, IO2, or IO3).
  • Returns a 12-bit value between 0 and 4095 (corresponding to 0V – 2.5V, due to the internal voltage reference).

Example: Reading a Potentiometer

If you connect a potentiometer to IO2, you can read its position with:

uint16_t potValue = myCodeCell.pinADC(2);
Serial.println(potValue);

Correct Potentiometer Wiring:

Since the maximum voltage on CodeCell’s ADC pins should not exceed 3.3V, you should connect the potentiometer to 3V3 instead of Vo:

3V3 → One end of the potentiometer  
GND → Other end of the potentiometer  
IO2 → Middle pin of the potentiometer  

Important: Internal Voltage Reference is 2.5V

The onboard microcontroller uses a 2.5V internal voltage reference. This means:

  • If your input voltage is 2.5V, the ADC reading will be 4095 (max value) - any voltage above 2.5V will be 4095
  • If your input voltage is 1.25V, the ADC reading will be around 2048.

To scale readings properly:

float voltage = (myCodeCell.pinADC(2) / 4095.0) * 2.5;
Serial.println(voltage);

Why Use This Function?

  • Works on IO1, IO2, and IO3 - flexibility in choosing ADC pins
  • No need for extra configuration - just call pinADC()
  • Built-in 12-bit resolution for precise readings.

Whether you're reading a potentiometer,  sensor, or other analog signals, CodeCell makes ADC reading easy. 

Voir l'article entier

CodeCell: Set Up a PWM in Seconds

CodeCell: Set Up a PWM in Seconds

Pulse Width Modulation (PWM) is essential for controlling LED brightness, motor speed, and even generating audio signals. With CodeCell, setting up PWM is incredibly simple using the pinPWM() function. Unlike traditional Arduino PWM that requires predefined pins and extra setup, CodeCell allows you to enable PWM on any of its 6 available pins effortlessly.

How to Use pinPWM()

To generate a PWM signal, use:

myCodeCell.pinPWM(uint8_t pin_num, uint16_t pin_freq, uint8_t pin_dutycycle);
  • pin_num → The pin you want to use (any of CodeCell's 6 available GPIOs).
  • pin_freq → The frequency of the PWM signal (in Hz).
  • pin_dutycycle → The duty cycle (0–100), representing the percentage of time the signal stays HIGH.

Example: Dimming an LED

Let’s say you want to dim an LED connected to pin 3 with a 1 kHz (1000 Hz) frequency and 50% brightness:

myCodeCell.pinPWM(3, 1000, 50);

To make the LED brighter (e.g., 80% brightness):

myCodeCell.pinPWM(3, 1000, 80);

Or to turn it off (0% brightness):

myCodeCell.pinPWM(3, 1000, 0);

Why Use This Function?

  • Works on Any of CodeCell’s 6 GPIOs - no restrictions.
  • No extra setup required - just call pinPWM() and you're ready to go.
  • Adjustable frequency and duty cycle - perfect for LEDs, motors, and more.

This function makes PWM control on CodeCell more flexible and easier than ever. Try it out in your next project!  

Voir l'article entier

CodeCell: Set Up a GPIO in Seconds

CodeCell: Set Up a GPIO in Seconds

The CodeCell module makes working with GPIO (Input/Output) pins simpler than ever. While you can still use the traditional Arduino digitalWrite() and digitalRead() functions, CodeCell library uses the pinWrite() and pinRead(), which automatically handle pin initialization for you.

No Pin Initialization

With CodeCell's optimized functions, you don’t need to manually set the pin mode using pinMode(). Just call:

myCodeCell.pinWrite(uint8_t pin_num, bool pin_value);

For example, to turn on an LED connected to pin 5:

myCodeCell.pinWrite(5, HIGH);

Or turn it off:

myCodeCell.pinWrite(5, LOW);

Reading GPIO States

Reading a pin state is just as simple:

if (myCodeCell.pinRead(5)) {
    // Pin is HIGH, do something
}

The pinRead() function returns a boolean (true for HIGH, false for LOW), making GPIO interactions effortless.

Why Use These Functions?

  • No need for pinMode()—it’s handled automatically, making your sketches cleaner.

  • Built-in error detection—if a pin is not available on your CodeCell module, it will issue an error on the Serial Monitor, helping you debug the problem.

These functions make CodeCell's GPIO management more intuitive—whether you're controlling LEDs, buttons, and more!

 

Voir l'article entier


1 2 3 Suivant »
Partage

Github

  • À propos
  • Software
  • Education
  • Contact
  • FAQ
  • Termes
  • Politique de remboursement
  • politique de confidentialité

Soyez le premier informé des nouveaux projets et bénéficiez d'offres intéressantes !

© 2025 Microbots.