Arduino 1-Wire Device Libraries

DS2450 Example Code - 4 Channel A/D

This example demonstrates the use of the library to continuously read all 4 a/d channels from a DS2450 sensor and print the values to the serial port.

#include <Arduino.h>
#include <OneWire.h>
#include <DS2450.h>

// define the Arduino digital I/O pin to be used for the 1-Wire network here
const uint8_t ONE_WIRE_PIN = 2;

// define the 1-Wire address of the DS2450 quad a/d here (lsb first)
uint8_t DS2450_address[] = { 0x20, 0x1C, 0x86, 0x00, 0x00, 0x00, 0x00, 0x9E };

OneWire ow(ONE_WIRE_PIN);
DS2450 ds2450(&ow, DS2450_address);

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

void loop() {
    ds2450.update();
    if (ds2450.isError()) {
        Serial.println("Error reading from DS2450 device");
    } else {
        for (int channel = 0; channel < 4; channel++) {
            Serial.print("Channel ");
            Serial.print(char('A' + channel));
            Serial.print(" = ");
            Serial.print(ds2450.getVoltage(channel), 1);
            if (channel < 3) {
                Serial.print("v, ");
            } else {
                Serial.println("v.");
            }
        }
    }
    delay(500);
}

<<Previous Page | Index | Next Page>>