Go Down

Topic: Arduino Mega with double 7 segment display (Read 7380 times) previous topic - next topic


You mean they have the POE board supplying 9V instead of 5 V regulated? :smiley-eek:


Well, I think so...

The current shield has a Power over Ethernet (PoE) module designed to extract power from a conventional twisted pair Category 5 Ethernet cable:

    IEEE802.3af compliant
    Low output ripple and noise (100mVpp)
    Input voltage range 36V to 57V
    Overload and short-circuit protection
    9V Output
    High efficiency DC/DC converter: typ 75% @ 50% load
    1500V isolation (input to output)

NB: the Power over Ethernet module is proprietary hardware not made by Arduino, it is a third party accessory. For more information, see the datasheet
But then when you look at the shield schematic... confusing... I can see a 3V3 regulator powered by a 5V rail, but can't figure out where that comes from. Perhaps the shield relies on the Arduino board's regulator to turn 9V into 5V, then it regulates that to 3V3 for its own chip.


Perhaps the shield relies on the Arduino board's regulator to turn 9V into 5V, then it regulates that to 3V3 for its own chip.
That's how I figured it, but is seems a very poor design.


That's how I figured it, but is seems a very poor design.

Agreed. I guess there wasn't a 5V version of the poe module available when they designed the shield.


So all the digits are now linked, which each segment through a 220+330R, and I modified the code to test it so that it counts up to 9999. All good. I am not using any pin from the Ethernet shield but was wondering if I can use the GND one, that should be fine right? all the others are from pins 14 to 49. Now I am going to start working on the code for the Ethernet Shield, let's see how far I get XD.

Also Do you think I can use the arduino 9V power supply to plug into a POE splitter and then the ethernet cable to power the entire system? so that I only have 1 cable around?

Example of POE Splitter


Feb 29, 2016, 05:57 pm Last Edit: Feb 29, 2016, 06:00 pm by PaulRB
Umm, if i understand you correctly, then no i don't think you can. The ethernet cable would then supply 9V to the shield, but that will be too low for the shield's poe module:
Input voltage range 36V to 57V
Or did you mean that you would use the splitter in the picture to extract the 9V from the ethernet cable and power the mega using that plugged into its barrel connector. That might work.


Yeah, that's a very basic POE splitter, but there are two concerns in using direct connection into the barrel jack.

One is that if you feed the working current down your Ethernet cable, you can lose a lot.  Proper POE uses a much higher voltage (up to 48 V), therefore at a lower current to reduce losses and a switchmode regulator to efficiently deliver the working voltage.  One external adapter I have offers switchable output voltages.

The other is that whilst the Ethernet signals run through isolation transformers, with that basic adapter, the ground connects directly from one end to the other so that the ground voltage at the distant end, due to the resistance, will be at a different potential to the source end.  If the distant equipment does not have a ground connection (an "island" unit on the ceiling or up a pole) that will not matter, but if it is connected to any other equipment, it could cause trouble.


Mar 01, 2016, 02:27 pm Last Edit: Mar 01, 2016, 02:36 pm by Rovers
I think I might leave this POE dilemma for the end, if it gets too complicated with different power supplies or other I'll just run 2 cables.
In the mean time I looked around on how to set up a code that would allow me to connect the arduino to the internet and, reading some data of a page, store them to display them. I found this code which seems to do exactly this (but around tweets) but don't really know how to convert it to my purposes. In particular I don't know how to tell the software which bit of data to read from the webpage, in my case next westbound train and next eastbound train. I imagine that once the code reads these value I should be able to save them and them display them without too many problem?

Code: [Select]
 Simple Web Data Client
 This sketch connects to a website using an Arduino Wiznet Ethernet shield,
 downloads a simple dataset, and does some LED fades based on the data.
 * Ethernet shield attached to pins 10, 11, 12, 13
 created december 2014
 by Nathan Yau, based on work by David A. Mellis, Tom Igoe, and Adrian McEwen

 This example code is in the public domain.

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
char server[] = "54,171,57,157";   
String dataLocation = "/overground/stop/910GHMPSTDH/hampstead-heath-rail-station?lineId=london-overground/ HTTP/1.1";

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
String currentLine = "";            // string for incoming serial data
String currRates = "";
boolean readingRates = false;       // is reading?
const int requestInterval = 600000; // milliseconds delay between requests

boolean requested;                  // whether you've made a request since connecting
long lastAttemptTime = 0;           // last time you connected to the server, in milliseconds

// LED Stuff //

// Variables for first LED
// int led1 = 3;                       // the pin that the LED is attached to
// int brightness1 = 0;                // how bright the LED is
// int maxBrightness1 = 100;           // how bright before turning fade
// int fadeAmount1 = 1;                // how many points to fade the LED by
// int delayTime1 = 40;
// float tweetsPerMin1 = 0;
// long lastFadeTime1 = 0;

// Variables for second LED
// int led2 = 5;         
// int brightness2 = 0;   
// int maxBrightness2 = 100;
// int fadeAmount2 = 1;   
// int delayTime2 = 40;
// float tweetsPerMin2 = 0;
// long lastFadeTime2 = 0;

// Variables for third LED
// int led3 = 9;
// int brightness3 = 0;
// int maxBrightness3 = 100;
// int fadeAmount3 = 1;
// int delayTime3 = 40;
// float tweetsPerMin3 = 0;
// long lastFadeTime3 = 0;

// Data baselines
float baselineRate = 500;          // Tweets per minute
int baselineDelay = 10;             // Milliseconds between fade increments
int minBrightness = 10;             // Minimum top brightness when fading

void setup() {

  // Open serial communications and wait for port to open:

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore

  // Connect to server 

  // LEDs
  // pinMode(led1, OUTPUT);
  // pinMode(led2, OUTPUT);
  // pinMode(led3, OUTPUT);


void loop() {

  // Set LED fade rates and brightness
  // analogWrite(led1, brightness1);
  // analogWrite(led2, brightness2);
  // analogWrite(led3, brightness3);

  // Fade accordingly for next iteration
  // if (millis() - lastFadeTime1 > delayTime1) {
  //   fadeByRate(tweetsPerMin1, brightness1, fadeAmount1, delayTime1, maxBrightness1, lastFadeTime1);
  // }
  // if (millis() - lastFadeTime2 > delayTime2) {
  //   fadeByRate(tweetsPerMin2, brightness2, fadeAmount2, delayTime2, maxBrightness2, lastFadeTime2);
  // }
  // if (millis() - lastFadeTime3 > delayTime3) {
  //   fadeByRate(tweetsPerMin3, brightness3, fadeAmount3, delayTime3, maxBrightness3, lastFadeTime3);
  // }

  // Checking for new data
  if (client.connected()) {
    if (client.available()) {
      // read incoming bytes:
      char inChar = client.read();

      // add incoming byte to end of line:
      currentLine += inChar;

      // if you get a newline, clear the line:
      if (inChar == '\n') {
        currentLine = "";

      if (currentLine.endsWith("<rates>")) {
        readingRates = true;
      else if (readingRates) {
        if (!currentLine.endsWith("</rates>")) { //'>' is our ending character
          currRates += inChar;
        else {
          readingRates = false;

          String justRates = currRates.substring(0, currRates.length()-8);

          // Split justRates
          int firstSpaceIndex = justRates.indexOf(" ");
          int secondSpaceIndex = justRates.indexOf(" ", firstSpaceIndex+1);
          String firstVal = justRates.substring(0, firstSpaceIndex);
          String secondVal = justRates.substring(firstSpaceIndex+1, secondSpaceIndex);
          String thirdVal = justRates.substring(secondSpaceIndex);

          // Convert strings to floats and store
          tweetsPerMin1 = strToFloat(firstVal);
          tweetsPerMin2 = strToFloat(secondVal);
          tweetsPerMin3 = strToFloat(thirdVal);

          // Reset for next reading
          currRates = "";

  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and two minutes have passed since
    // your last connection, then attempt to connect again:

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(server, 80)) {
    Serial.println("making HTTP request...");
    // make HTTP GET request to dataLocation:
    client.println("GET " + dataLocation);
    client.println("Host: projects.flowingdata.com");
  // note the time of this connect attempt:
  lastAttemptTime = millis();

// Calculate brightness and maxBrightness based on rate.
void fadeByRate(float& tweetsPerMin, int& brightness, int& fadeAmount, int& delayTime, int& maxBrightness, long& lastFadeTime) {

  // maxBrightness between 80 and 255
  maxBrightness = min( max(round(tweetsPerMin / baselineRate * 255), minBrightness), 255 );

  // Blink lightly if low rate
  if (maxBrightness == minBrightness) {
    if (brightness == 0) {
      brightness = minBrightness; 
      delayTime = round(5000 * tweetsPerMin / 100);
    else {
      brightness = 0;
      delayTime = 5000;

  // Fade otherwise
  else {
    delayTime = 40;
    // Reverse direction when faded out or at maxBrightness
    if (brightness == 0) {
      fadeAmount = abs(fadeAmount);
    else if (brightness >= maxBrightness) {
      fadeAmount = -abs(fadeAmount);
      delayTime = round(10000 * tweetsPerMin / baselineRate);

    // Adjust brightness.
    brightness += fadeAmount;

  lastFadeTime = millis();

float strToFloat(String str) {
  char carray[str.length() + 1];           // determine size of array
  str.toCharArray(carray, sizeof(carray)); // put str into an array
  return atof(carray);

P.S. Just wondering: should I open a new topic in the Network section of the forum or keep posting here under this topic? I already looked in that section and didn't find a topic similar to this.


Looks like a reasonable example, although there is a lot of stuff about fading leds that is not relavent.

Your next task is to figure out what your data looks like. Load up the page with the train times in your browser. Then view the html. Most browsers allow you to do this from one of their menus. Next, spot the tiny bits of data you need in what is probably a sea of html codes. You need to find some "markers", bits of text nearby your data, that are always there in the same place. If you can find some, these will act as keywords for the Arduino code to pick up and use to find the train time data.

Post the link to the web page of interest and we will have a look also.


Mar 01, 2016, 03:47 pm Last Edit: Mar 01, 2016, 03:56 pm by Rovers
Something like?
Code: [Select]
<span class="live-board-eta">Due</span>
<span class="live-board-eta">4</span>
<span class="live-board-eta">8</span>

would 'live-board-eta' work as a keyword? I just realised that it will probably be tricky to tell the Arduino to distinguish between the different destinations of the trains, although each train has a 'data-destination-id'.

By the way the page is https://tfl.gov.uk/overground/stop/910GHMPSTDH/hampstead-heath-rail-station?lineId=london-overground


Mar 01, 2016, 05:26 pm Last Edit: Mar 01, 2016, 05:48 pm by PaulRB
That looks hopeful. I think you will also need to be able to spot where the platform 1 and platform 2 sections of the page start. Then the Arduino can find the first occurrance of 'live-board-eta' in each section.

I see these:
Code: [Select]
<div class="live-board-subboard" data-platform-id="1">


Since there was too much LED dimming and extra stuff in the previous example I found this other one which seems to be made exactly to communicate to 'THINGSPEAK'. I tried to add the part to 'scan' the page with 'String readPage()' but now I get a compiling error in a part of the code I didn't even touch.

Code: [Select]
 Arduino --> ThingSpeak Channel via Ethernet
 The ThingSpeak Client sketch is designed for the Arduino and Ethernet.
 This sketch updates a channel feed with an analog input reading via the
 ThingSpeak API (https://thingspeak.com/docs)
 using HTTP POST. The Arduino uses DHCP and DNS for a simpler network setup.
 The sketch also includes a Watchdog / Reset function to make sure the
 Arduino stays connected and/or regains connectivity after a network outage.
 Use the Serial Monitor on the Arduino IDE to see verbose network feedback
 and ThingSpeak connectivity status.
 Getting Started with ThingSpeak:
   * Sign Up for New User Account - https://thingspeak.com/users/new
   * Create a new Channel by selecting Channels and then Create New Channel
   * Enter the Write API Key in this sketch under "ThingSpeak Settings"
 Arduino Requirements:
   * Arduino with Ethernet Shield or Arduino Ethernet
   * Arduino 1.0+ IDE
  Network Requirements:
   * Ethernet port on Router   
   * DHCP enabled on Router
   * Unique MAC Address for Arduino
 Created: October 17, 2011 by Hans Scharler (http://www.nothans.com)
 Additional Credits:
 Example sketches from Arduino team, Ethernet by Adrian McEwen

#include <SPI.h>
#include <Ethernet.h>

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "4SJEJJ51EMI28WBJ";
const int updateThingSpeakInterval = 10 * 1000;      // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;

// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()
  // Start Serial for debugging on the Serial Monitor
  // Start Ethernet on Arduino

void loop()
  // Read value from Analog Input Pin 0
  String analogValue0 = String(analogRead(A0), DEC);
  // Print Update Response to Serial Monitor
  if (client.available())
    char c = client.read();

  String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory


    if (client.available()) {
      char c = client.read();

      if (c == '<span class="live-board-eta">' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part
      }else if(startRead){

        if(c != ' mins</span>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
          //got what we need here! We can disconnect now
          startRead = false;
          return inString;

  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected)
  // Update ThingSpeak
  if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
  // Check if Arduino Ethernet needs to be restarted
  if (failedCounter > 3 ) {startEthernet();}
  lastConnected = client.connected();

void updateThingSpeak(String tsData)
  if (client.connect(thingSpeakAddress, 80))
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");

    lastConnectionTime = millis();
    if (client.connected())
      Serial.println("Connecting to ThingSpeak...");
      failedCounter = 0;
      Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");   
    Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");   
    lastConnectionTime = millis();

void startEthernet()

  Serial.println("Connecting Arduino to network...");

  // Connect to network amd obtain an IP address using DHCP
  if (Ethernet.begin(mac) == 0)
    Serial.println("DHCP Failed, reset Arduino to try again");
    Serial.println("Arduino connected to network using DHCP");

For now I'd be happy to have the arduino print out a number as a result. Anyone can point me in the right direction?

It should connect to this page I made using 'Thingspeak': https://api.thingspeak.com/apps/thinghttp/send_request?api_key=4SJEJJ51EMI28WBJ


Hmmm... I'm no expert on Thingspeak, but I think you may have misunderstood what it is all about. Someone please correct me if wrong, but I thought the idea of Thingspeak was that values read from sensors connected to the Arduino could be posted onto the internet and displayed as graphs etc.

So I'm not sure its a better starting point than the previous example, despite all the led dimming stuff.

Go Up