Recent Posts

Pages: 1 ... 8 9 [10]
Where did you get the board from? Have you got a link?

I'm trying to merge to example found on playground together.

I want to both use the sd card web server


and the NTP sync example on the time library.

both sketch works well alone but in the same sketch, it froze in the setup.

Im using Arduino due whith an ethernet shield.
Thats my sketch so far.

Code: [Select]

#include <Time.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <EthernetUdp.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 110); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80
IPAddress timeServer(132, 163, 4, 101); //
File webFile;

const int timeZone = -5;  // Eastern Standard Time (USA)
EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

void setup()
  Serial.begin(9600);       // for debugging
  Ethernet.begin(mac, ip);  // initialize Ethernet device
  server.begin();           // start to listen for clients
  Serial.print("Ip address; "); Serial.println(Ethernet.localIP());
  if (Ethernet.begin(mac) == 0) {
    // no point in carrying on, so do nothing forevermore:
    while (1) {
      Serial.println("Failed to configure Ethernet using DHCP");

     // initialize SD card
     Serial.println("Initializing SD card...");
     if (!SD.begin(4)) {
         Serial.println("ERROR - SD card initialization failed!");
         return;    // init failed
     Serial.println("SUCCESS - SD card initialized.");
     // check for index.htm file
     if (!SD.exists("index.htm")) {
         Serial.println("ERROR - Can't find index.htm file!");
         return;  // can't find index file
     Serial.println("SUCCESS - Found index.htm file.");
  Serial.println("waiting for sync");
  //  setSyncProvider(getNtpTime);
  pinMode(10, OUTPUT);


time_t prevDisplay = 0; // when the digital clock was displayed

void loop()

  if (Serial.available() > 0) ; {

    if (timeStatus() != timeNotSet) {
      if (now() != prevDisplay) { //update the display only if time has changed
        prevDisplay = now();

    EthernetClient client = server.available();  // try to get client

      if (client) {  // got client?
          boolean currentLineIsBlank = true;
          while (client.connected()) {
              if (client.available()) {   // client data available to read
                  char c =; // read 1 byte (character) from client
                  // last line of client request is blank and ends with \n
                  // respond to client only after last line received
                  if (c == '\n' && currentLineIsBlank) {
                      // send a standard http response header
                      client.println("HTTP/1.1 200 OK");
                      client.println("Content-Type: text/html");
                      client.println("Connection: close");
                      // send web page
                      webFile ="index.htm");        // open web page file
                      if (webFile) {
                          while(webFile.available()) {
                              client.write(; // send web page to client
                  // every line of text received from the client ends with \r\n
                  if (c == '\n') {
                      // last character on line of received text
                      // starting new line with next character read
                      currentLineIsBlank = true;
                  else if (c != '\r') {
                      // a text character was received from client
                      currentLineIsBlank = false;
              } // end if (client.available())
          } // end while (client.connected())
          delay(1);      // give the web browser time to receive the data
          client.stop(); // close the connection
      } // end if (client)

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(" ");

void printDigits(int digits) {
  // utility for digital clock display: prints preceding colon and leading 0
  if (digits < 10)

/*-------- NTP code ----------*/

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets

time_t getNtpTime()
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time

// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);


I posted about this project a while ago for help, but I've run into a new problem, so I'm back!

I am trying to control a stepper motor using the Sparkfun EasyDriver and a three-way switch. When I have the switch in one position it is supposed to spin the motor one way, when it's in the opposite position it's supposed to spin the other way, and when it's in the middle the motor's supposed to stop.

I'm having trouble getting that last part to work right. I've been playing around with different ways for a couple weeks now, from switch/case declarations to if/else statements. Nothing seems to work right. The code that has been working best for the first two conditions above is attached here. The problem is that when the switch is in the middle it acts as if it were position B.

I don't know if my problem is because I'm not telling the code how to turn off the motor right or if it's not acknowledging that the switch is in the middle position right, but something's not working here.

Here's my code:

Code: [Select]
#include "Arduino.h"

const int posA = 4;     // Position A pin
const int posB = 5;     // Position B pin

int dirpin = 2;
int steppin = 3;

void setup()
pinMode(posA, INPUT);    // set posA as input 
pinMode(posB, INPUT);    // set posB as input
digitalWrite(posA, HIGH);
digitalWrite(posB, HIGH);      //Sets step pin as an output
pinMode(dirpin, OUTPUT);       //Sets direction pin as an output
pinMode(steppin, OUTPUT);
void loop()
int stateA = digitalRead(posA);     // variables for reading the switches status
int stateB = digitalRead(posB);

//If the switch is turned to side A it should rotate as direction LOW
  if(stateA == HIGH){
    digitalWrite(dirpin, LOW);
    digitalWrite(steppin, LOW);
    digitalWrite(steppin, HIGH);
 //If the switch is turned to side B it should rotate as direction HIGH
  else if(stateB == HIGH){
    digitalWrite(dirpin, HIGH);
    digitalWrite(steppin, LOW); 
    digitalWrite(steppin, HIGH);
  //If the switch is in the middle it should now rotate, because step pin does not alternate to create a "rising edge"
  else if(stateA == LOW && stateB == LOW){
    digitalWrite(dirpin, LOW);
    digitalWrite(steppin, LOW);

Attached is a picture of how my breadboard is wired up. Any help would be appreciated. Thanks!

Project Guidance / pc tablet internet arduino bot
Last post by midmofarmer - Today at 01:37 am
tablet or pc connect to wifi or internet to control and monitor arduino robot, gotta be a free way to do it
Hardware / Re: Arduino uno v3+ adafruit m...
Last post by Brunello - Today at 01:35 am
Perche' i 42BYGHW811 sono motori da 2,5A, e le schede con diver A4988 sono fatte per motori che assorbono poco piu' della la meta' di quella corrente.
Anche alettandole e raffreddandole bene non riesci a sfruttare a pieno il motore
Programming Questions / Move an array in runtime
Last post by myownway - Today at 01:35 am
Hi there, I'm making an lcd menu class, this is what I have for the moment. I know that it's wrong but you kinda get the idea there. What would you guys do? How would you guys move the array from the constructor to the array inside the class? Thanks

Code: [Select]
struct MENULIST {
  String item;
  void (*ptrFunc)();

MENULIST main_menu_items[] = {
{"ITEMONE", ItemOneFunction},
{"ITEMTWO", ItemTwoFunction}

class Menu{
    Menu(MENULIST items[]){
      current_item_selected = 0;
      menu_items = items;
    void next(){
      if (((sizeof(menu_items)/sizeof(menu_items[0])) - 1) == current_item_selected){
       current_item_selected = 0;
      } else {
    void prev(){
      if (current_item_selected == 0){
        current_item_selected = ((sizeof(menu_items)/sizeof(menu_items[0])) - 1);
      } else {
    String get(){
      return menu_items[current_item_selected].item;
    void run(){
    int current_item_selected;
    MENULIST menu_items[];
void ItemOneFunction(){
void ItemTwoFunction(){
/* ^^ MENU FUNCTIONS ^^ */
Sensors / DHT22 Webserver
Last post by DancesWithWords - Today at 01:34 am
I'm trying to get the following code to work for me:

Code: [Select]
#include <SPI.h> 
#include <Wire.h> 
#include <Ethernet.h> 
//#include <UIPEthernet.h> 
#include <DHT.h> 
#include <stdio.h> 
dht DHT; 
#define DHT22_PIN 2 
float combined_temp_C; 
float combined_temp_F;  //create a new variable 
byte TempHi;              // Variable hold data high byte 
byte TempLo;              // Variable hold data low byte 
boolean P_N;              // Bit flag for Positive and Negative 
boolean P_N112; 
boolean P_N212; 
unsigned int Decimal;     // Variable hold decimal value 
char * strTempC = NULL; 
 char * strTempF = NULL; 
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x4E, 0x10 };  // MAC address 
byte ip[]  = { 192, 168, 1, 203 };                     // ip-address, please change to fit your network 
byte mydns[] = { 192, 168, 1, 1 };             
byte gateway[] = { 192, 168, 1, 1 };               
byte subnet[] = { 255,255,255,0 };   
EthernetServer server(80); 
static char output[300] = ""; 
void setup() { 
   Ethernet.begin(mac, ip); 
   Serial.print("server is at "); 

char headerHTML[] = "HTTP/1.1 200 OK\r\n" 
          "Content-Type: text/html\r\n" 
          "Connection: close\r\n" 
          "Refresh: 5\r\n" 
          "<!DOCTYPE HTML>" 
          "<Title>RBBS Server</Title>" 
 char footerHTML[] = "</html>" ; 
 char * TimeElapsed() { // Was Home Page 
  long t = millis() / 1000; 
  word h = t / 3600; 
  byte m = (t / 60) % 60; 
  byte s = t % 60; 
  sprintf(output, "<h1>%d%d:%d%d:%d%d</h1>" , h/10, h%10, m/10, m%10, s/10, s%10); 
  return output; 

 void sendTempToNetwork(EthernetClient myClient) 
      // now humidity / temp sensor 
    int chk = DHT.read22(DHT22_PIN); 
    myClient.print(DHT.temperature, 0); 
    myClient.write(" "); 
    myClient.print(dewPoint(DHT.temperature,DHT.humidity), 0); 
    myClient.write(" "); 
 void sendAnalogToNetwork(EthernetClient myClient) 
    // output the value of each analog input pin for good measure 
    for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 
      int sensorReading = analogRead(analogChannel); 
      myClient.print("analog input "); 
      myClient.print(" is "); 
      myClient.println("<br />");         
 * Main Loop
void loop()   

// listen for incoming clients 
  EthernetClient client = server.available(); 
  if (client) { 
    Serial.println("new client"); 
    // an http request ends with a blank line 
    boolean currentLineIsBlank = true; 
    while (client.connected()) { 
      if (client.available()) { 
        char c =; 
        // 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) { 
          // send a standard http response header 
          // now send the stuff we want 
          client.print(TimeElapsed()); // your old code here 
          // do some more stuff 
           // were done sending so now send the footer to close the page 
        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 
    // close the connection: 
    Serial.println("client disconnected"); 

void Cal_Temp() 

  if (TempHi&0x80)     // If bit7 of the TempHi is HIGH then the temperature is negative 
    P_N = 0; 
  else       // Else the temperature is positive 
  P_N = 1; 
  TempHi = TempHi & 0x7F;   // Remove sign 
  TempLo = TempLo & 0xF0;   // Filter out last nibble 
  TempLo = TempLo >>4; // Shift right 4 times 
  Decimal = TempLo; 
  Decimal = Decimal * 625;  // Each bit = 0.0625 degree C 
  combined_temp_C= TempHi + TempLo*.0625; 
  combined_temp_F = combined_temp_C*1.8+32; 
   sprintf(strTempC, "%f", combined_temp_C); 
   sprintf(strTempF, "%f", combined_temp_F); 

////Celsius to Kelvin conversion 
//double Kelvin(double celsius) 
//        return celsius + 273.15; 
// dewPoint function NOAA 
// reference:   
double dewPoint(double celsius, double humidity) 

        double A0= 373.15/(273.15 + celsius); 
        double SUM = -7.90298 * (A0-1); 
        SUM += 5.02808 * log10(A0); 
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ; 
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ; 
        SUM += log10(1013.246); 
        double VP = pow(10, SUM-3) * humidity; 
        double T = log(VP/0.61078);   // temp var 
        return (241.88 * T) / (17.558-T); 

// delta max = 0.6544 wrt dewPoint() 
// 5x faster than dewPoint() 
// reference: 
double dewPointFast(double celsius, double humidity) 

        double a = 17.271; 
        double b = 237.7; 
        double temp = (a * celsius) / (b + celsius) + log(humidity/100); 
        double Td = (b * temp) / (a - temp); 
        return Td; 

However I'm getting a number of errors:

sketch_nov26b.ino:7:1: error: 'dht' does not name a type
sketch_nov26b.ino: In function 'void sendTempToNetwork(EthernetClient)':
sketch_nov26b.ino:56:18: error: expected primary-expression before '.' token
sketch_nov26b.ino:58:23: error: expected primary-expression before '.' token
sketch_nov26b.ino:62:23: error: expected primary-expression before '.' token
sketch_nov26b.ino:67:32: error: expected primary-expression before '.' token
sketch_nov26b.ino:67:48: error: expected primary-expression before '.' token

If you can help I'd appreciate it.  Thanks


Code was taken from:
I would be happy to perform an error check.

I believe it sends the value once. However, I have a program where I can send messages - on/off, color, etc - and that does not register a new LED blink. I tested this program with a working DMX fixture and it does send correctly. So I believe it is after the software and into the Arduino side of things.

How can I use a println() here? I want to see it on the console not read a value from a pin. Is there one to use on the console side?

Also, here is a video description of the problem:

Code: [Select]
#include <Conceptinetics.h>

// Number of slave DMX channels

// Configure a DMX slave controller
DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS );

const int ledPin = 13;

// the setup routine runs once when you press reset:
void setup() {             

  // Enable DMX slave interface and start recording
  // DMX data
  dmx_slave.enable (); 

  // Set start address to 1, this is also the default setting
  // You can change this address at any time during the program
  dmx_slave.setStartAddress (1);

  // Set led pin as output pin
  pinMode ( ledPin, OUTPUT );

// the loop routine runs over and over again forever:
void loop()

  // If the first channel comes above 50% the led will switch on
  // and below 50% the led will be turned off

  // NOTE:
  // getChannelValue is relative to the configured startaddress
  if ( dmx_slave.getChannelValue (1) > 127 )
    digitalWrite ( ledPin, HIGH );
    digitalWrite ( ledPin, LOW );

  Println(dmx_slave.getChannelValue (1));


In Windows 8.1.

I was able to upload, both from Windows and from a RPi but now I can't - not sure what's happened. I'm now trying to upload from Windows 8.1.

Back when I was able to upload from Windows, connecting the Arduino would trigger the 'new USB device' sound, then the 'USB disconnected' sound would play, followed by the 'new USB device' sound. I think this is something to do with how the Arduino micro interfaces via USB either as a bootloader, or as the running Arduino (no clear idea what exactly is going on).

Anyway, now this is what happens:
Plug in Arduino Micro.
USB connected sound plays. "Arduino micro bootloader (COM6)" appears briefly in Device Manager.
USB disconnected sound plays. No sign of Arduino.

After that, there's no COM port visible in device manager, so no port can be selected in Arduino IDE.

I attempted resetting the Arduino 'during upload' to see if this would make uploading work. However it leads to Arduino IDE sitting forever 'Uploading' to no avail.

Any ideas how to fix my Arduino Micro?

Hmm - from the Troubleshooting Guide:

Make sure there's a bootloader burned on your Arduino board. To check, reset the board. The built-in L LED (which is connected to pin 13) should blink. If it doesn't, there may not be a bootloader on your board.

I see no blinking LED any more. No bootloader? Not sure how that could have happened.

Also, for your code, try to put this in your while loop:
Code: [Select]
lcd_key = read_LCD_buttons();
Now it will update the value while it is looping so if you press the select button it will stop.
Pages: 1 ... 8 9 [10]