I have a project where I have a Leonardo with an ethernet shield and an RS485 shield stacked. The RS485 controls electro-mechanical digits for a scoreboard sending info it gets via the ethernet connection. If I power the Leonardo via the USB connector, either from the laptop or an Amazon charger, everything works fine. However if I power it from the barrel connector it all stops working after a few seconds. I have tried a 9V and a 12V supply to the barrel and the results are the same. Any ideas?
Please post proper schematics.
Thanks for the speedy reply. What do you want schematics of? I thought I explained the setup clearly, apologies if not.
Schematics of the electrical wiring. Links to the data sheets of the shields.
Word sallad is not good enough for engineering matters.
Ethernet Shield Arduino Ethernet Shield 2 — Arduino Official Store
RS485 shield RS422 RS485 Shield for Arduino | The Pi Hut
Does this help?
No. Sales sites are no good. Technical data are needed. Data sheets.
Datasheet_RS485_shield_Rev_B_EN(1).pdf (677.3 KB)
arduino-Ethernet-Shield2-V2-sch(1).pdf (77.1 KB)
Any good?
So don't power it from the barrel connector, but do it properly. Get a 5V power supply and power the Arduino and the different modules parallel; i.e. don't let the Arduino convert 9/12V or whatever down to 5V and supply it to all kinds of equipment because Arduino boards aren't made to do that kind of thing.
Thank you. If I understand you correctly, are you suggesting that I take 5v directly to the 5V and ground pins because otherwise all the current is being taken via the Arduino voltage regulator?
Does your code contain while(!Serial) or similar and makes use of Serial output to the PC.
Native USB can sometimes be tricky. Please post your code (and please use code tags when posting code) so we can have a look for other possible pitfalls.
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();
}
*/
Indeed, that sums it up pretty nicely!
Thanks to all who have contributed. I have learned something today.
Let's hope things clear up and the project runs.
Replying to #2 had shown What reply #12 said. That's life.
Just be aware that you should not power on the 5V pin and at the same time have USB connected. This applies to boards that use a FET to switch power between Vin and USB
Thanks
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.