There is no serial output to the PC in the working version. I do have another version for testing that does output to the serial monitor.
/*
Ethernet Web Server For Cricket Scoreboard Using Flipdots Digits
*** NOTE. Comms to RS485 on Uno Wifi Rev 2 is lon Serial1***
Connections on Joy-It RS 485 board is A to + B to -
Added checking for scoreboard blanking by testing for 'Z' 6/6/2020
Added DLS for PCSPRO 8/04/2021
Changed Test Print to print actual digits rather than ASCII 8/11/2021
Added PCSPRO integration with Scoreboard App v5.5 13/6/21
Channel Assignments for Flipdots Digits
Bat 1 H = 0
Bat 1 T = 1
Bat 1 U = 2
Total H = 3
Total T = 4
Total U = 5
Bat 2 H = 6
Bat 2 T = 7
Bat 2 U = 8
Wkt = 9
Overs T = 10
Overs U = 11
First H = 12
First T = 13
First U = 14
DLS H = 15
DLS T = 16
DLS U = 17
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 2, 201);
byte send_data_buffer [] = { 0xAA, 0x56, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00 }; // template and space defintion for 15 digits connected
// protocol: AA / 56 / number of digits (in this example we have 18 digits, therefore we send 18-1 = 0x11 / offset - keep it always 0x00 / address keep it 0x00 / data... / checksum
int n;
EthernetServer server(80);
char text[150]; // string that holds the input from the laptop
int index = 0; // counter for incrementing the read of the client input
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
pinMode (4, OUTPUT);
digitalWrite (4, HIGH); //Turn off SD card
Ethernet.init(10); // Most Arduino shields
Serial1.begin(9600); // initialize serial communication to serial one for RS485
/* If needed to test wifi connection over serial monitor on laptop. Enable the next line otherwise comment out*/
//Serial.begin(9600);
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
////Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
//Serial.println("Ethernet cable is not connected.");
}
// start the server
server.begin();
//Serial.print("server is at ");
//Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
//Serial.println("new client"); // print a message out the serial . Only needed for testing
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read();
if (index < 150) // reads the digits from the laptop and
{ // converts them to a string
text[index] = c;
index++;
text[index] = '\0';
}
// read a byte, then
// Serial.write(c); // print it out the serial monitor only needed to check reception from Laptop
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.stop();
// Serial.println("client disconnected"); //only needed for testing. Comment out for live use.
delay(10);
index = 0;
// Extracts the digits from the data string
int Bat1Ones = (text[25]);
int Bat1Tens = (text[24]);
int Bat1Hundreds = (text[23]);
int Bat2Ones = (text[31]);
int Bat2Tens = (text[30]);
int Bat2Hundreds = (text[29]);
int RunsOnes = (text[37]);
int RunsTens = (text[36]);
int RunsHundreds = (text[35]);
int WktsOnes = (text[43]);
int OversOnes = (text[49]);
int OversTens = (text[48]);
int FirstOnes = (text[55]);
int FirstTens = (text[54]);
int FirstHundreds = (text[53]);
int DLSOnes = (text[61]);
int DLSTens = (text[60]);
int DLSHundreds = (text[59]);
ProcessDigitsHarborne(Bat1Hundreds, Bat1Tens, Bat1Ones, Bat2Hundreds, Bat2Tens, Bat2Ones, RunsHundreds, RunsTens, RunsOnes, OversTens, OversOnes, WktsOnes, FirstHundreds, FirstTens, FirstOnes , DLSHundreds, DLSTens, DLSOnes);
}
}
void send_number(int digit1, int digit2, int digit3, int digit4, int digit5, int digit6, int digit7, int digit8, int digit9, int digit10, int digit11, int digit12, int digit13, int digit14, int digit15 , int digit16, int digit17, int digit18)
{ // Sends the data to the scoreboard via RS485 Comment out next line for live use
//Serial.println ("Sending RS485 Data ");
int checksum = 0x00;
//Next line does not change however many digits.
for (n = 0; n < 5; n++) Serial1.write(send_data_buffer[n]); // header, number of digits, offset 0 and first address 0
Serial1.write(digit1); // digit 1
Serial1.write(digit2); // digit 2
Serial1.write(digit3); // digit 3
Serial1.write(digit4); // digit 4
Serial1.write(digit5); // digit 5
Serial1.write(digit6); // digit 6
Serial1.write(digit7); // digit 7
Serial1.write(digit8); // digit 8
Serial1.write(digit9); // digit 9
Serial1.write(digit10); // digit 10
Serial1.write(digit11);// digit 11
Serial1.write(digit12);// digit 12
Serial1.write(digit13);// digit 13
Serial1.write(digit14); // digit 14
Serial1.write(digit15); // digit 15
Serial1.write(digit16);// digit 16
Serial1.write(digit17); // digit 17
Serial1.write(digit18); // digit 18
checksum = digit1 + digit2 + digit3 + digit4 + digit5 + digit6 + digit7 + digit8 + digit9 + digit10 + digit11 + digit12 + digit13 + digit14 + digit15 + digit16 + digit17 + digit18;
checksum = checksum % 0x100;
Serial1.write(checksum); // checksum = digit
//Comment out next line for live use
//Serial.println ("RS485 Data Sent");
delay(10);
}
void ProcessDigitsHarborne(int Bat1Hundreds, int Bat1Tens, int Bat1Ones, int Bat2Hundreds, int Bat2Tens, int Bat2Ones, int RunsHundreds, int RunsTens, int RunsOnes, int OversTens, int OversOnes, int WktsOnes, int FirstHundreds, int FirstTens, int FirstOnes, int DLSHundreds, int DLSTens, int DLSOnes )
{
// Next if statement checks for scoreboard blanking by checking for ASCII 90 and sends null to all digits
if (Bat1Hundreds == 90) // Check if hundreds is 'Z'
{ Bat1Hundreds = 0; // Blank digits (nul)
Bat1Tens = 0;
Bat1Ones = 0;
Bat2Hundreds = 0;
Bat2Tens = 0;
Bat2Ones = 0;
RunsHundreds = 0;
RunsTens = 0;
RunsOnes = 0;
OversTens = 0;
OversOnes = 0;
WktsOnes = 0;
FirstHundreds = 0;
FirstTens = 0;
FirstOnes = 0;
DLSHundreds = 0;
DLSTens = 0;
DLSOnes = 0;
}
// Checks for leading zeros and blanks the digits by sending nul
if (Bat1Hundreds == 48) // Check if hundreds is zero
{ Bat1Hundreds = 0; // Blank Leading zero for bat 1 hundreds (nul)
if (Bat1Tens == 48) // Check if tens is also zero
{ Bat1Tens = 0; // Blank Leading zero for bat 1 tens (nul)
}
}
if (Bat2Hundreds == 48) // Check if hundreds is zero
{ Bat2Hundreds = 0; // Blank Leading zero for bat 2 hundreds (nul)
if (Bat2Tens == 48) // Check if tens is also zero
{ Bat2Tens = 0; // Blank Leading zero for bat 2 tens (nul)
}
}
if (RunsHundreds == 48) // Check if hundreds is zero
{ RunsHundreds = 0; // Blank Leading zero for runs hundreds (nul)
if (RunsTens == 48) // Check if tens is also zero
{ RunsTens = 0; // Blank Leading zero for runs tens (nul)
}
}
if (FirstHundreds == 48) // Check if hundreds is zero
{ FirstHundreds = 0; // Blank Leading zero for First hundreds (nul)
if (FirstTens == 48) // Check if tens is also zero
{ FirstTens = 0; // Blank Leading zero for First tens (nul)
if (FirstOnes == 48) // Check if units is also zero
{ FirstOnes = 0; // Blank First ones
}
}
}
if (DLSHundreds == 48) // Check if hundreds is zero
{ DLSHundreds = 0; // Blank Leading zero for First hundreds (nul)
if (DLSTens == 48) // Check if tens is also zero
{ DLSTens = 0; // Blank Leading zero for First tens (nul)
if (DLSOnes == 48) // Check if units is also zero
{ DLSOnes = 0; // Blank First ones
}
}
}
if (OversTens == 48) // Check if overs tens is zero
{ OversTens = 0; // Blank Leading zero for First tens (nul)
}
// Next line only needed for testing. Comment out for live use.
// TestPrint (Bat1Hundreds, Bat1Tens, Bat1Ones, Bat2Hundreds, Bat2Tens, Bat2Ones, RunsHundreds, RunsTens, RunsOnes, OversTens, OversOnes, WktsOnes, FirstHundreds, FirstTens, FirstOnes, DLSHundreds, DLSTens, DLSOnes);
send_number(Bat1Hundreds, Bat1Tens, Bat1Ones, RunsHundreds, RunsTens, RunsOnes, Bat2Hundreds, Bat2Tens, Bat2Ones, WktsOnes, OversTens, OversOnes, FirstHundreds, FirstTens, FirstOnes , DLSHundreds, DLSTens, DLSOnes);
}
/*
void TestPrint (int Bat1Hundreds, int Bat1Tens, int Bat1Ones, int Bat2Hundreds, int Bat2Tens, int Bat2Ones, int RunsHundreds, int RunsTens, int RunsOnes, int OversTens, int OversOnes, int WktsOnes, int FirstHundreds, int FirstTens, int FirstOnes, int DLSHundreds, int DLSTens, int DLSOnes)
// Prints digits (ASCII) to serial monitor for testing only.
{
//Serial.print ("Bat One ");
Serial.write (Bat1Hundreds);
Serial.write (Bat1Tens);
Serial.write(Bat1Ones);
//Serial.println();
//Serial.print ("Bat Two ");
Serial.write (Bat2Hundreds);
Serial.write (Bat2Tens);
Serial.write(Bat2Ones);
//Serial.println();
//Serial.print ("Total ");
Serial.write (RunsHundreds);
Serial.write (RunsTens);
Serial.write(RunsOnes);
//Serial.println();
//Serial.print ("Wkts ");
Serial.write (WktsOnes);
//Serial.println();
//Serial.print ("Overs ");
Serial.write (OversTens);
Serial.write (OversOnes);
//Serial.println();
//Serial.print ("First Innings ");
Serial.write (FirstHundreds);
Serial.write (FirstTens);
Serial.write(FirstOnes);
//Serial.println();
//Serial.print ("DLS Par ");
Serial.write (DLSHundreds);
Serial.write (DLSTens);
Serial.write(DLSOnes);
//Serial.println();
}
*/