how to program the citycoco controller

How to Program CityCoco Controller: A Step-by-Step Guide

By Anthony Taylor
AD

Embracing the future of urban mobility, the CityCoco controller offers unparalleled opportunities for developers to create innovative electric skateboard (ESK8) experiences. This comprehensive guide will walk you through the process of programming the CityCoco controller, ensuring a smooth and seamless integration into your next project.

Before we dive in, let's make sure you have the essential tools and knowledge. Familiarize yourself with C/C++ programming - it's crucial for understanding this guide's code snippets. You'll also need an Arduino development environment, a CityCoco controller, and the accompanying Arduino shield.

Setting Up Your Development Environment

The first step towards programming the CityCoco controller is setting up your development environment. Begin by installing the Arduino IDE, which will serve as your primary coding platform. Once installed, ensure you have the correct board selected (Arduino Uno under Tools > Board) and your port is configured (Tools > Port).

AD
Kerbal Controller
Kerbal Controller
a control panel with multiple buttons and knobs on top of a white table next to a computer
a control panel with multiple buttons and knobs on top of a white table next to a computer
How to Build a Low Cost Temperature Controller? Simple Circuit Idea for a DIY Temperature Controller
How to Build a Low Cost Temperature Controller? Simple Circuit Idea for a DIY Temperature Controller

Next, obtain the CityCoco controller's libraries and sample code. These resources provide invaluable foundations for your project. You can find them on the official CityCoco website or other trusted sources.

Configuring Your Arduino IDE

To optimize your Arduino IDE for CityCoco development, you'll need to install specific libraries. The CityCoco library is the core component, providing essential functions for interacting with the controller. Other useful libraries include AccelStepper and MotorLib. Install them via Sketch > Include Library > Manage Libraries.

How To Get Better on Controller 🎮 Settings Tutorial for PC & Console (Fortnite PS5)
How To Get Better on Controller 🎮 Settings Tutorial for PC & Console (Fortnite PS5)
an electronic circuit diagram with many different parts labeled in red, blue and green wires
an electronic circuit diagram with many different parts labeled in red, blue and green wires

Additionally, adjust your IDE's settings to accommodate the CityCoco controller's power requirements. In your sketch, set the board voltage to 5V under Tools > Board. Enable the 'Allow direct port access' and 'Tooling' options under File > Preferences.

Hardware Connections

Connecting your CityCoco controller and Arduino shield is a straightforward process. Mount the shield onto your Arduino board, ensuring proper alignment. Then, connect the controller's motor leads to the shield's respective headers (M1, M2, M3, and M4). Power both devices via the shield's barrel jack, using a 12V to 24V DC adapter.

AD

Lastly, connect your Arduino board to your computer using a USB cable. Make sure to conserve the shield's USB port for attaching debugging tools like an oscilloscope or logic analyzer.

Programming the CityCoco Controller

Now that your development environment is configured, it's time to dive into programming the CityCoco controller. We'll begin with the basic setup and gradually introduce more complex functionalities.

In your main sketch, include the necessary CityCoco library and initialize the controller using the appropriate pin configuration. Here's a sample code snippet to get you started:

AD
```cpp #include // CityCoco connections const int dirPin1 = 5; const int dirPin2 = 6; const int stepPin1 = 2; const int stepPin2 = 3; // Initialize CityCoco instance CityCoco myCoco = CityCoco(dirPin1, dirPin2, stepPin1, stepPin2); ```

Basic Motors Setup and Movement

To control each motor independently, you can use the move() function to set their speeds and directions. Positive values speed up, while negative values slow down and reverse the motor. Here's an example of moving both motors forward at half speed:

```cpp void setup() { myCoco.move(128, 128); // Motor 1 and Motor 2 forward at half speed } void loop() { // Your loop code here } ```

For fine-tuned speed control, use the setSpeed() and getSpeed() functions. The speed value ranges from 0 to 255, representing motor speeds from off to full power.

Advanced Motor Control: PWM and Microsteps

The CityCoco controller allows for advanced motor control via pulse-width modulation (PWM) and microstepping. These features enable precise speed and acceleration adjustments, ensuring smooth and responsive ESK8 performance.

To take advantage of PWM, utilize the enablePWM() function and modify your motor speed values using setSpeedPWM(). Similarly, enable microstepping with enableMicrostep() and adjust microstep values accordingly.

Combine these functionalities to create optimized motor control algorithms for your ESK8 projects. For a deep dive into PWM and microstepping, refer to the CityCoco documentation and community forums.

Integrating Sensors and Feedback

Enhance your ESK8 designs by incorporating sensors and feedback features. The CityCoco controller supports a range of sensors, including encoders, gyroscopes, accelerometers, and Hall effect sensors. Integrating these components allows you to monitor skateboard movement, detect obstacles, and optimize performance.

Before connecting any sensors, consult their respective datasheets for proper pin configurations. Once your sensors are connected, use the CityCoco library's built-in functions to read sensor data. For example, to read encoder values, use the getEncoderClicks() function:

```cpp long encoderClicks = myCoco.getEncoderClicks(); ```

Sensor Feedback for Smart Maneuvers

Use sensor feedback to create intelligent ESK8 maneuvers. For instance, employ accelerometer data to maintain consistent speed during inclines or declines. To access accelerometer data, first enable it using accelerometerBegin(), then read it with accelerometerRead():

```cpp myCoco.accelerometerBegin(); float ax, ay, az; myCoco.accelerometerRead(&ax, &ay, &az); ```

Adjust your motor speeds based on the accelerometer values to account for inclination changes.

Other sensor integrations, like obstacle detection with ultrasonic sensors or gyroscope-based balancing, require similar approaches - enabling, reading, and interpreting sensor data to optimize motor control.

Real-Time Debugging and Logging

Debugging and logging are crucial for identifying issues and monitoring performance in your ESK8 projects. Utilize Serial communication for real-time debugging by enabling the SERIAL define in your sketch, like so:

```cpp #define SERIAL ```

Once enabled, log motor speeds, sensor data, and other relevant information using Serial.print() or Serial.println(). Monitor these values in the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to fine-tune your ESK8 designs.

As you delve into programming the CityCoco controller, you'll discover its immense potential for transforming electric skateboard projects. This comprehensive guide sets you on the path to developing innovative, responsive, and engaging ESK8 experiences. Happy coding!

AD