7
Arduino 4-20 mA + RTC Shield MCI-MA-0088 SHIELD INSTALLATION Before starting to work with the Arduino 4-20mA + RTC Shield, the following installation procedure must be done: A. Position the Shield. a. Note that the pin headers that connect the Shield to the Arduino have only one position. B. Connect the Shield to the Arduino main board. C. Connect the Jumpers depending on the transmitter type. a. For type 3 transmitters connect Jumpers W1-W4 depending on the channels to be connected. b. For type 2 and 3 transmitters disconnect the Jumpers W1-W4 depending on the channels to be connected. D. Connect the 4-20mA current signal to the desired channel. E. If required, connect the sensor supply voltage to the V OUT terminal. F. Connect the Arduino main board to the PC using the USB cable. G. Connect the Arduino main board 9-12 [VDC] 600mA power supply. H. Run the arduino sample code. www.ekt 2 .com

Arduino 4-20 mA + RTC Shield

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Arduino 4-20 mA + RTC Shield

Arduino 4-20 mA + RTC Shield

MCI-MA-0088

SHIELD

INSTALLATION

Before starting to work with the Arduino 4-20mA + RTC Shield, the following

installation procedure must be done:

A.

Position the Shield.

a.

Note

that the pin headers that connect the Shield to the Arduino

have only one position.

B.

Connect the Shield

to the Arduino main board.

C.

Connect the Jumpers depending on the transmitter type.

a.

For type 3 transmitters connect Jumpers W1-W4 depending on the

channels

to be connected.

b.

For type 2 and

3 transmitters disconnect the Jumpers W1-W4

depending on the channels to be connected.

D.

Connect the 4-20mA current signal to

the desired channel.

E.

If required, connect the sensor supply voltage to the V OUT terminal.

F.

Connect the Arduino main board to the PC using the USB cable.

G.

Connect the Arduino main board 9-12 [VDC] 600mA power supply.

H.

Run the arduino sample code.

w w w . e k t 2 . c o m

Page 2: Arduino 4-20 mA + RTC Shield

AB

C

D

E

Arduino 4-20 mA + RTC Shield assembly.

Using a 12mm Coin type battery (MCI-PRT-00677) is recommended to maintain

the time configuration on the Real Time Clock embedded with the Arduino 4-20 mA +

RTC Shield in case of a power supply fault.

PORT MAPPING

The I/O ports used by the Arduino 4-20mA + RTC Shield cannot be used by

another shield, with the exception of SDA, SCL and RESET signals.

Pin Name Function

ANALOG 0 AN1 Channel 1 analog input

ANALOG 1 AN2 Channel 2 analog input

ANALOG 2 AN3 Channel 3 analog input

ANALOG 3 AN4 Channel 4 analog input

ANALOG 4/SDA SDA SDA signal for communication with Real Time Clock

ANALOG 5/SCL SCL SCL signal for communication with Real Time Clock

RESET RESET_ARD Arduino board reset

ELECTRICAL CHARACTERISTICS

9-12 VDC power supply.

100mA maximum current. (not considering transmitters power consumption)

MECHANICAL CHARACTERISTICS

Dimensions (WidthxLengthxHeight) 54x69x11 [mm]

w w w . e k t 2 . c o m

Page 3: Arduino 4-20 mA + RTC Shield

Arduino Sample Code:

Description: Evaluation code for the Arduino 4-20 mA Shield. This code reads the 4 input channels and shows the system time on Serial Monitor. Target Device: Arduino Duemilanove, Uno, Mega ================================================================================== Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. // ================================================================================== // // Original by E.I. // // Ver | dd mmm yyyy | Author | Description // =====|=============|========|===================================================== // 1.00 | 16 Nov 2010 | E.I. | First release // ==================================================================================*/ #include <string.h>

w w w . e k t 2 . c o m

#include <stdio.h> #include <ctype.h> #include "Wire.h" #define DS1307_I2C_ADDRESS 0x68

Page 4: Arduino 4-20 mA + RTC Shield

//Variables char generalBuffer[80]; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; void Date2Str(char* buf) { if(dayOfMonth < 10) *(buf++) = '0'; itoa(dayOfMonth,buf,10); buf+=strlen(buf); *(buf++) = '/'; if(month < 10) *(buf++) = '0'; itoa(month,buf,10); buf+=strlen(buf); strcpy(buf,"/20"); buf+=strlen(buf); itoa(year,buf,10); } void Time2Str(char* buf) { if(hour < 10) *(buf++) = '0'; itoa(hour,buf,10); buf+=strlen(buf); *(buf++) = ':'; if(minute < 10) *(buf++) = '0'; itoa(minute,buf,10); buf+=strlen(buf); *(buf++) = ':'; if(second < 10) *(buf++) = '0'; itoa(second,buf,10);

}

w w w . e k t 2 . c o m

//Functions void setup() { Wire.begin(); Serial.begin(9600); if(ReadDs1307(0x08) != 0xaa) { second = 0; minute = 0; hour = 12;

Page 5: Arduino 4-20 mA + RTC Shield

dayOfWeek = 1; dayOfMonth = 1; month = 9; year = 10; SetDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); WriteDs1307(0x08,0xaa); } } // Convert normal decimal numbers to binary coded decimal byte DecToBcd(byte val) { return ( (val/10*16) + (val%10) ); } // Convert binary coded decimal to normal decimal numbers byte BcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } // 1) Sets the date and time on the ds1307 // 2) Starts the clock // 3) Sets hour mode to 24 hour clock // Assumes you're passing in valid numbers void SetDateDs1307(byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7

byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.send(DecToBcd(second)); // 0 to bit 7 starts the clock Wire.send(DecToBcd(minute)); Wire.send(DecToBcd(hour)); // If you want 12 hour am/pm you need to set // bit 6 (also need to change readDateDs1307) Wire.send(DecToBcd(dayOfWeek)); Wire.send(DecToBcd(dayOfMonth)); Wire.send(DecToBcd(month)); Wire.send(DecToBcd(year)); Wire.endTransmission(); }

w w w . e k t 2 . c o m

Page 6: Arduino 4-20 mA + RTC Shield

// Gets the date and time from the ds1307 void GetDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) { // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // A few of these need masks because certain bits are control bits *second = BcdToDec(Wire.receive() & 0x7f); *minute = BcdToDec(Wire.receive()); *hour = BcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm *dayOfWeek = BcdToDec(Wire.receive()); *dayOfMonth = BcdToDec(Wire.receive()); *month = BcdToDec(Wire.receive()); *year = BcdToDec(Wire.receive()); } void WriteDs1307(byte address,byte data) { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(address); Wire.send(data);

Wire.endTransmission(); } byte ReadDs1307(byte address) { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(address); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 1); return Wire.receive(); } float Get_ma(int channel) { float mA = 0.0f; int value = analogRead(channel); float voltage = (analogRead(channel) * 5.0f) / 1024.0f; if(voltage < 0.9f) return mA; mA = (voltage + 0.03f) * 4.0f; if(mA > 20.0f) mA = 20.0f; return mA; }

w w w . e k t 2 . c o m

Page 7: Arduino 4-20 mA + RTC Shield

char *ftoa(char *a, double f, int precision) { long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000}; char *ret = a; long heiltal = (long)f; itoa(heiltal, a, 10); while (*a != '\0') a++; *a++ = '.'; long desimal = abs((long)((f - heiltal) * p[precision])); itoa(desimal, a, 10); return ret; } void PrintHeader() { Serial.println("Test 4-20ma + RTC Arduino Shield"); Serial.print("DATE: "); GetDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Date2Str(generalBuffer); Serial.println(generalBuffer); Serial.print("TIME: "); Time2Str(generalBuffer); Serial.println(generalBuffer); delay(1000); } void loop() { int channel = 0; PrintHeader(); while(1) { strcpy(generalBuffer,"CH"); char *pMatch = generalBuffer + strlen(generalBuffer); itoa(channel,pMatch,10); strcat(generalBuffer,":"); pMatch = generalBuffer + strlen(generalBuffer); float ma = Get_ma(channel); ftoa(pMatch, ma, 1); Serial.println(generalBuffer); delay(1000); if(++channel > 3) { PrintHeader(); channel = 0; } }; } w w w . e k t 2 . c o m