Maker.io main logo

Roller Mill Remote Scale Display

2021-07-10 | By M5Stack

License: General Public License Arduino

* Thanks for the source code and project information provided by @Eathan Rethmeier

 

Story
 

 

 
 
 
 
 
 
Code
 
Copy Code
//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);
}
}
}
制造商零件编号 A093
DIGITAL RGB LED WEATHERPROOF STR
M5Stack Technology Co., Ltd.
制造商零件编号 A093-B
DIGITAL RGB LED WEATHERPROOF STR
M5Stack Technology Co., Ltd.
制造商零件编号 A093-C
DIGITAL RGB LED WEATHERPROOF STR
M5Stack Technology Co., Ltd.
制造商零件编号 A093-D
DIGITAL RGB LED WEATHERPROOF STR
M5Stack Technology Co., Ltd.
制造商零件编号 K046
ATOM RS232 KIT
M5Stack Technology Co., Ltd.
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum