With this post we open the new category “Test files”, which is a sort of repository for testing and experimenting with Archiduino. Every test file contains the results of real experiments, not just theory. We hope this will be of any help to the growing family of Archiduino (and – why not? – Arduino) users. So, let’s start!

Test file #1 – How to build a small web server using Archiduino and the Ethernet ENC28J60 SnipCard

Premises

In order to work properly, an Ethernet interface running on Archiduino (as well as on equivalent Arduino boards) needs some libraries that aren’t too small. This is the first – and thoughest – challenge for the old, dear, (too) small Atmel ATMega32U4. In past months we built a nice Ethernet interface (with ENC28J60) for the Archimede project. Recently we thought: why don’t we use it on Archiduino too? Has the CPU enough resources to drive it? Well, this test file is the answer.

What do we need?

Test file #1 - BOM (Bill of materials)

QuantityItemDescriptionNotes#module
1CPUArchiduino CPU ATMega32U4Needs hardware configuration (CN10 and JP6, see notes)CPU socket
1BASE BOARDArchiduino Base Board
1ETHERNETEthernet SnipCardM9
1ADCADC SnipCardM7
1LCDLCD Card with keyboardOptional, but usefulLCD socket

Hardware configuration

The CPU needs to be adapted in order to fit the Ethernet interface cable. As you can see in pictures, we have to solder the small Gadgeteer connector on CN10. The orientation notch must be placed towards the ATMega32U4 chip.

JP6 schematic

JP6 schematic

We need to close the jumper JP6 on pins 1-2, with a solder drop. About connector placement and soldering: it’s very small, not everybody has the skills or tools to solder it properly. But… no fear, if you want to run this experiment and you buy Archiduino and SnipCards, we provide – as default – every connector placed and working.

JP6 jumper for ethernet connector

JP6 jumper for ethernet connector

Software

To write the sketch we simply adapted an example found attached to the UIPEthernet libraries. The program reads a voltage regulated by a potentiometer on pin M7A and a photoresistance on pin M7B, via the ADC SnipCard (which has as default two inputs: one designed for analog voltage measurement 0-10VDC, the other for a resistive load like photoresistor, NTC, PT1000 etc.). Both values are displayed on the LCD and  sent to the http web server. The server is configured to work at a fixed IP (in the sketch it is 10.0.0.10, change it according to your needs). When we open the IP in the browser, we can see the values displayed in the html page.

In the example there is also an alert system which send on the serial port informations about connection ad disconnection. You can obviously adapt it to your environment, or exclude it to save flash space.

#include <Archiduino.h>
#include <ArchiduinoLcd.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
	
#include <UIPEthernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                      
IPAddress ip(10, 0, 0, 10);                        
EthernetServer server(80);
ArchiduinoLcd_PCF lcd;

int rele = RELE_11;

float VA = 0;
float VB = 0;
    
int cnt;

void setup() {
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();

  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  pinModeEx(rele, OUTPUT);
  
  lcd.init();                      // initialize the lcd 
  lcd.begin(16, 2);                // initialize lcd and keyboard
  lcd.clear();
  
  lcd.backlight();
  lcd.print("   ARCHIDUINO   ");
  lcd.setCursor(0, 1);
  lcd.print(" TEST ETHERNET  ");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print(Ethernet.localIP());  
  
  pinMode(M7A, INPUT);
  pinMode(M7B, INPUT);
  
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  delay(500);
  cnt++;
  Serial.println(cnt);
  ADA();
  
  if (client)
  {  
    Serial.println("-> New Connection");

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;

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

        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          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>");
          // output the value of each analog input pin
          //for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
          //  int sensorReading = analogRead(analogChannel);
            client.print("M7A ");
            client.print(VA);
            client.println("<br />");
            client.print("M7B ");
            client.print(VB);
            client.println("<br />");
          //}
          client.println("</html>");
          break;
          
          break;
        }

        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

    // give the web browser time to receive the data
    delay(10);

    // close the connection:
    client.stop();
    Serial.println("   Disconnected\n");
    digitalWrite(rele, HIGH);
  }
}

/* ------------------------------------------------------------------------------------------------------------------------------- */

void ADA(){
  
  int Lettura_M7A = analogRead(M7A);    
  int Lettura_M7B = analogRead(M7B);   
  
  VA = Lettura_M7A / 100.0;
  lcd.setCursor(0,1);
  lcd.print("A:");  
  lcd.print(VA , 2);
  lcd.print("V ");   

  VB = (Lettura_M7B / 1000.0 * 100.0) + 5.0;  
  if (VB > 100) VB = 100;
  VB = 100 - VB; // converto in percentuale di luce
  
  lcd.setCursor(9,1);  
  lcd.print("B:");  
  lcd.print(VB , 1);
  lcd.print("%  ");   
  
  delay(10);
  
}

 

Considerations

After uploading the sketch, the available flash space is just about 2 Kbytes. This could be a problem if we consider to implement a complex firmware. But, if we need to display a set of values coming from Archiduino I/Os, even if they are related to every possible channel of the system, the space is enough to do that.

Pictures