Eathan Rethmeier
Published © GPL3+

Roller Mill Remote Scale Display

A practical use of the M5Stack Atom RS232 as part of a remote display.

IntermediateWork in progress2 days32
Roller Mill Remote Scale Display

Things used in this project

Hardware components

M5stack Atom RS232
×1
M5Stack SK6812 Digital RGB LED Strip
Requires extra Grove cables.
×7
eoocvt DC Converter Buck Module 12V Convert to 5V USB Output Power Adapter
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Display Sketch

Arduino
//5_14_2021
//Smart Scale

//todo list
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include "M5Atom.h"

// Fields
uint8_t res;
//const char* ssid = "";
//const char* password = "";
//const char* hostname = "";
//const byte DNS_PORT = 53;
//IPAddress apIP( 192, 168, 4, 1 );
//DNSServer dnsServer;

//User defined stored data
int Scale_Type = 1;
int Scale_Color = 0;
String ch = "";

//neopixel pin designation
#define PIN 26

// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the matrix; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
//     rows or in vertical columns, respectively; pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
//     in the same order, or alternate lines reverse direction; pick one.
//   See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_GRBW    Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)


// Example for NeoPixel Shield.  In this application we'd like to use it
// as a 5x8 tall matrix, with the USB port positioned at the top of the
// Arduino.  When held that way, the first pixel is at the top right, and
// lines are arranged in columns, progressive order.  The shield uses
// 800 KHz (v2) pixels that expect GRB color data.
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(29, 8, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  NEO_RGB           + NEO_KHZ800);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 255, 0) };

//uint16_t Serial_Output;

void setup() {

    M5.begin();
  // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert)
  Serial2.begin(9600, SERIAL_8N1, 22, 19);
  //Serial2.begin(9600, 22, 19);
//
//  #if defined(ESP32)
//  WiFi.setHostname( hostname );
//#else
//  WiFi.hostname( hostname );
//#endif
//
//  // try to connect to existing network
//  WiFi.begin( ssid, password );
//  Serial.print(F( "\n\nTry to connect to existing network") );
//
//  {
//    uint8_t timeout = 20;
//
//    // Wait for connection, 5s timeout
//    do {
//      delay( 500 );
//      Serial.print( "." );
//      timeout--;
//    } while ( timeout && WiFi.status() != WL_CONNECTED );
//
//    // not connected -> create hotspot
//    if ( WiFi.status() != WL_CONNECTED ) {
//      Serial.print( F("\n\nCreating hotspot") );
//
//      WiFi.mode( WIFI_AP );
//      WiFi.softAPConfig( apIP, apIP, IPAddress( 255, 255, 255, 0 ) );
//      WiFi.softAP( "ScaleDisplay");
//
//      timeout = 5;
//
//      do {
//        delay( 500 );
//        Serial.print( "." );
//        timeout--;
//      } while ( timeout );
//    }
//  }
//
//  dnsServer.start( DNS_PORT, "*", apIP );
//
//  /////
//  Serial.println( "\n\nWiFi parameters:" );
//  Serial.print( "Mode: " );
//  Serial.println( WiFi.getMode() == WIFI_AP ? "Station" : "Client" );
//  Serial.print( "IP address: " );
//  Serial.println( WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP() );
//
//
//  uint16_t tab1 = ESPUI.addControl( ControlType::Tab, "Settings 1", "Scale" );
//   uint16_t tab2 = ESPUI.addControl( ControlType::Tab, "Settings 2", "Settings" );
//   
//Serial_Output =ESPUI.addControl( ControlType::Label, "Scale", "", ControlColor::Turquoise, tab1 );
//  
//  
//  
//  ESPUI.begin("Scale");
//  // put your setup code here, to run once:
//matrix.setTextColor(matrix.Color(7,0,0));
  matrix.setBrightness(64);
}

//
int x= matrix.width();
int pass = 0;

//

void loop() {
  // put your main code here, to run repeatedly:
   //dnsServer.processNextRequest();
 if(Serial2.available()) {
  {
    //ch = Serial2.readStringUntil((''));
    ch = Serial2.parseInt();
    //ch.trim();
  // Serial.print(ch);
  // Serial.flush();
//   ESPUI.updateControlValue(Serial_Output, ch);
   //M5.dis.drawpix(0, 0x00ffff);
   M5.update();
   delay(50);
 //LED Matrix update
  matrix.fillScreen(0);
  matrix.setCursor(0, 0);
    matrix.setTextColor(colors[pass]);
  matrix.print(ch);
  matrix.show();

  delay(100);
 }
 }
}

Credits

Eathan Rethmeier

Eathan Rethmeier

0 projects • 0 followers

Comments