M5Stamp C3 programming examples
-
When will there be M5Stamp C3 programming examples? Interested in turning on the LED in different colors.
-
Hello @AucT
if you are familiar with ESP-IDF you probably could modify the ESP-IDF blink example to change colors as well.
Thanks
Felix -
They are coming once a stable setup and guide can be created.
-
These examples would be very much appreciated. I've been having trouble getting ESP-IDF or Arduino IDE to flash any code to my M5Stamp-C3 since there are virtually no examples of how to do this on the internet.
-
@trrevvorr That is the problem I am finding.
IDF is a nightmare to install and configure. -
@trrevvorr said in M5Stamp C3 programming examples:
M5Stamp-C3
While I realise it's a different core but I've been having fun with the M5Stamp-Pico which does use the same LED controller so I wonder if this will help with the ops question.
I use the Arduino-IDE and the FastLed module. I've attached a snippet of code where the LED is White while searching for the wifi and Green when connected. It then flashes Blue when data is received.
More about FastLed can be found here:
https://github.com/FastLED/FastLED
https://github.com/FastLED/FastLED/wiki/Pixel-reference#chsv// Load Wi-Fi, Servo and Led libraries
#include <WiFi.h>
#include <ESP32Servo.h>
#include <FastLED.h>
#include <Preferences.h>// number of leds on board and data pin
#define NUM_LEDS 1
#define LED_DATA_PIN 27
// Define the array of leds
CRGB leds[NUM_LEDS];//Create Servo Object
Servo servo;// Setup network credentials
const char* ssid = "SMCS";
const char* password = "**********";// Set web server port number to 80
WiFiServer server(80);// Variable to store the HTTP request
String header;// Auxiliar variables to store the current output state
String SliderValue = "0"; // Contains returned value of Speed Slider range 0-1023
int Speed = 180; // Contains Integer value of Speed Slider range 0-180 deg for Servo
int OldSpeed = 180; // Contains previous speed
int Index; // String indexunsigned long time_now = 0; // Used to calculate time outs
String EngineName = "Millie"; // Engine name// Assign output variables to GPIO pins
// M5 Stamp pin to GPIO Mapping used by Train Controller
// 5v positive 5 volt supply
// Gnd Ground Supply
// G32 GPI32 Servo Pinconst int ServoPin = G32; // Servo Drive GPI32
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;// Set-up
void setup() {// Initialize the output variables as outputs
// Start with motor Drive control
servo.attach(ServoPin);// Start the serial monitor
Serial.begin(115200);// Set up Fastled and turn it To White
FastLED.addLeds<SK6812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
leds[0] = CRGB::White;
FastLED.show();// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
leds[0] = CRGB::Green;
FastLED.show();
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();}
// Main program
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
leds[0] = CRGB::Blue; // Go Blue
FastLED.show();
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client -
@silentmonkey said in M5Stamp C3 programming examples:
@trrevvorr said in M5Stamp C3 programming examples:
M5Stamp-C3
While I realise it's a different core but I've been having fun with the M5Stamp-Pico which does use the same LED controller so I wonder if this will help with the ops question.
I use the Arduino-IDE and the FastLed module. I've attached a snippet of code where the LED is White while searching for the wifi and Green when connected. It then flashes Blue when data is received.
More about FastLed can be found here:
https://github.com/FastLED/FastLED
https://github.com/FastLED/FastLED/wiki/Pixel-reference#chsv// Load Wi-Fi, Servo and Led libraries
#include <WiFi.h>
#include <ESP32Servo.h>
#include <FastLED.h>
#include <Preferences.h>// number of leds on board and data pin
#define NUM_LEDS 1
#define LED_DATA_PIN 27
// Define the array of leds
CRGB leds[NUM_LEDS];//Create Servo Object
Servo servo;// Setup network credentials
const char* ssid = "SMCS";
const char* password = "**********";// Set web server port number to 80
WiFiServer server(80);// Variable to store the HTTP request
String header;// Auxiliar variables to store the current output state
String SliderValue = "0"; // Contains returned value of Speed Slider range 0-1023
int Speed = 180; // Contains Integer value of Speed Slider range 0-180 deg for Servo
int OldSpeed = 180; // Contains previous speed
int Index; // String indexunsigned long time_now = 0; // Used to calculate time outs
String EngineName = "Millie"; // Engine name// Assign output variables to GPIO pins
// M5 Stamp pin to GPIO Mapping used by Train Controller
// 5v positive 5 volt supply
// Gnd Ground Supply
// G32 GPI32 Servo Pinconst int ServoPin = G32; // Servo Drive GPI32
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;// Set-up
void setup() {// Initialize the output variables as outputs
// Start with motor Drive control
servo.attach(ServoPin);// Start the serial monitor
Serial.begin(115200);// Set up Fastled and turn it To White
FastLED.addLeds<SK6812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
leds[0] = CRGB::White;
FastLED.show();// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
leds[0] = CRGB::Green;
FastLED.show();
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();}
// Main program
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
leds[0] = CRGB::Blue; // Go Blue
FastLED.show();
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the clientThank you for the demo but alas the Pico and C3 are two different chips. The Pico runs on Tensilica cores while the C3 runs on a RISCV core.
-
Hello @silentmonkey
thank you for your idea. Unfortunately the FastLED library doesn't seem to be adapted for the ESP32C3 yet. At least a couple of days ago, when I tried to compile it for the ESP32C3, it wouldn't w/o error.
What worked for me instead was the Adafruit_NeoPixel library.
Thanks
Felix -
@felmue Yes confirm. this latest version library works! Here is the blink code
#include <Adafruit_NeoPixel.h>#define PIXELPIN 2
#define NUMPIXELS 1Adafruit_NeoPixel pixel(NUMPIXELS, PIXELPIN, NEO_GRBW + NEO_KHZ400);
void setup() {
pixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixel.clear(); // Set pixel colors to 'off'
pixel.show();
}void loop() {
pixel.setPixelColor(0, pixel.Color(0, 0, 128));
pixel.show();
delay(1000);pixel.clear();
pixel.show();
delay(500);pixel.setPixelColor(0, pixel.Color(128, 0, 0));
pixel.show();
delay(1000);pixel.clear();
pixel.show();
delay(500);
} -
@auct Thank you! After adding the Adafruit neopixel library to the arduino IDE, this worked great!
I'll also note that I had issues flashing code to the C3 with my Mac (running OSX Catalina with updated drivers) but using a Windows machine fixed that issue.
-
I updated @auct's code to include the built in button as well:
#include <Adafruit_NeoPixel.h> #define BUTTON_PIN 3 #define PIXEL_PIN 2 #define NUM_PIXELS 1 Adafruit_NeoPixel pixel(NUM_PIXELS, PIXEL_PIN, NEO_GRBW + NEO_KHZ400); bool currentButtonPressed = false; void setup() { // set up serial out Serial.begin(115200); // set up neopixel pixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) pixel.clear(); // Set pixel colors to 'off' pixel.show(); // set up GPIO pinMode(BUTTON_PIN, INPUT_PULLUP); // initial button pressed state setPixelToCurrentButtonState(); } void loop() { // read button state (LOW when pressed) bool newButtonPressed = digitalRead(BUTTON_PIN) == LOW; setPixelStateIfChanged(newButtonPressed); delay(10); // debounce } void setPixelStateIfChanged(bool newButtonPressed) { if (newButtonPressed != currentButtonPressed) { currentButtonPressed = newButtonPressed; setPixelToCurrentButtonState(); } } void setPixelToCurrentButtonState() { if (currentButtonPressed) { Serial.println("turning LED blue"); pixel.setPixelColor(0, pixel.Color(0, 0, 128)); pixel.show(); } else { Serial.println("turning LED red"); pixel.setPixelColor(0, pixel.Color(128, 0, 0)); pixel.show(); } }
-
I have an IDF demo ready but the OSX driver issue is driving me bonkers on Catalina and yet to get the demo uploaded to the C3
-
Hello @ajb2k3
What worked for me on macOS Big Sur 11.5.2 is using the ESP32C3 built-in USB via GPIO18 and GPIO19.
What also worked for me on macOS Big Sur 11.5.2 was downloading and installing this driver CH9102_VCP_SER_MacOS from here. After a reboot and plugging in M5StampC3 via USB this port show up
/dev/cu.wchusbserial...
(in addition to/dev/cu.usbmodem...
which did not work).Thanks
Felix -
@felmue said in M5Stamp C3 programming examples:
Hello @ajb2k3
What worked for me on macOS Big Sur 11.5.2 is using the ESP32C3 built-in USB via GPIO18 and GPIO19.
What also worked for me on macOS Big Sur 11.5.2 was downloading and installing this driver CH9102_VCP_SER_MacOS from here. After a reboot and plugging in M5StampC3 via USB this port show up
/dev/cu.wchusbserial...
(in addition to/dev/cu.usbmodem...
which did not work).Thanks
FelixHello Felix
read here for a possible solution.