What's new
  • As of today ICMag has his own Discord server. In this Discord server you can chat, talk with eachother, listen to music, share stories and pictures...and much more. Join now and let's grow together! Join ICMag Discord here! More details in this thread here: here.

First Project with SainSmart Equip

Status
Not open for further replies.
C

Curare Widow

Hello Arduino Growing Friends

First I must say that I had worried me SainSmart equipment only because of wrong recommendations.
Today, I would recommend every newcomer to the Arduino world, even the original hardware. The original Arduino hardware is a little more expensive, but a beginner can avoid a lot of trouble.
Example: http://www.mikrocontroller.net/topic/273121

But I will still try to show how far I have come with the SainSmart scrap. In the beginning, I still thought everything is OK!
Of course I have read myself once smart.


and RTC for Time, DHT11 for Temp/RLF Module

No idea of C + + I then remained on the side of Henning Clarsen.
http://www.henningkarlsen.com/electronics/index.php
Caution! There is only support for Arduino original equipment.

The usual pages about Arduino should indeed be familiar to anyone
http://arduino.cc

Next, I informed myself about graphics and raw files.
In addition I have been experimenting around with Gimp.
http://www.gimp.org
At first it was a lot of stress at once. I had no idea of C + + and the graphics also no secret levels. After many trials and experiments, I then got it like that with the graphics could work on the touch screen.
So I tried through the use of raw graphics to make the source code clean and simple. As a beginner, it may be awkward but as a SainSmart mega 2560 r3 also has a limited memory.

So in the end I made ​​a few icons and graphics with Gimp together. For the icons, I simply used the beautiful iconset from here.
http://gnome-look.org/content/show.php/Sphere?content=158778

Everyone can even imagine that I would have never worried favourite moment during this time the Arduino or SainSamrt equipment. I only knew WinCC and S7 from Siemens, so that I could get through the industry standards and fewer problems. Unfortunately the equipment from Siemens is also considerably more expensive. Furthermore, is not necessary and too expensive for the private mini Grower such industry standard. I wanted to build, not just painting by numbers indeed himself. I got it now ...

So we look at what I have built to date. All Images are in My Profile Album



Unfortunately, I still have problems with the SD card or is it a problem lies in the source code. I need to investigate more.

Read from the SD card works well, but strange things happen when you save everything on SD-Card.
At the end the file system of the SD card is still readable. There is something with the "tinyFat" Library not, or my understanding of C + + is not enough.
Alternatively, I could still use 512 byte memory of the chip.
Maybe someone has the same equipment and also problems when saving the data on the SD card. I am convinced that I have problems because of the cheap chips. My Shield is also v1.0 from SainSmart but i have no Problems to Connect the Card .... ^^

Soon I'm going to build an enclosure. A test run will be bringing a few more results soon.

Caution!
And please, no questions about the source code. I'll summarize at the end of this project, all in a zip. (mayby at along the Christmas time 2014)
But now I already know that no one could use the zip. Because Arduino is something even build at the end. Perhaps this project is someone some inspiration or help to make something new. In the end, everyone has to be your own source code to build your own project so that the whole can be Understood.

Update coming soon ...
 
C

Curare Widow

Hello Arduino Grower
Today I want to quickly give you an overview.

Equipment: http://myworld.ebay.de/profit_vanity
1x Sain Smart Arduino Mega 2560 r3
1x 3-2-TFT-Touch-LCD-SD-Reader
1x TFT-Shield


1x RTC
2x DHT11

Sensors for ph & ec value and the level sensor for the tank or mixing plant for the fertilizer to make other people thought. My projects are simply too small for so much technology.

So first I got to thinking about the images for the touch screen. After several attempts I found a way to bake me a few images. The beautiful tool Gimp has helped me.
In the picture you can see how I have the images saved in the end. Later, I edited all the images on the website of Henning Karlsen with the Converter. (.jpg to .raw)



Next, I arranged the necessary libraries from Henning Clarsen Website (tinyFAT, UTFT, UTFT_Buttons, UTFT_Geometry, UTFT_tinyFAT, UTouch, DS1307 & relay8 for later use).
Now I could try with the Arduino firstonce the example sketches. As I understand now how do I use the touch screen I started to construct suitable functions to the .raw images.

.... It will soon build a suitable enclosure time.
 
C

Curare Widow

Today I have changed something in the images because there has been an update of the icons.
Many THANKS to the author potzblitz7.



On the screen shot looks like everyone I complicated the images to save.
Save as 16 bit bmp -> Save for Web in jpg with Skip Exif, then turning to the website of Henning Claarsen to change the jpg in a raw.
There is certainly also a professional solutions but I am not a graphic designer.

For the optical gimmick with the graph I have now a few lines painted on the screen, RLF is *2 at y-Skala. I have no time to take care of a matching box ...
I still need to build a grow box equipment also still missing. I hope at Christmas time I have everything ready.

 
C

Curare Widow

In the beginning I worked a plexiglass disc. I have an old electric fuse disassembled to get to the spring mechanism.

Now I can simply remove the plexiglass disc and install as an electrical fuse.

My Arduino gear I then set up easy.


My next step is the installation of my touch screen display in the lid of my box.


I will continue to report whether my Arduino sketch running well.
I'm curious how it will work.
 

minds_I

Active member
Veteran
Hello all,

I am also fooling around with Arduino and 1-wire devices for grow room implementation.

I am beginning to get a handle on C++ and the C derivative the Arduino uses. I also have the same arduino clone as you and have not had any issue with not functioning as expected.

That said, my coding skilz are very antiquated (Fortran/Basic/Qbasic/Assembly) and C++ seems almost like a foreign language.

All of the above programming languages aer process oriented while C++ is a object oriented.

Ok, this had me confused for the longest time. C++, to me, is just more complicated and the syntax is confounding to me. Object oriented programming is hard for me to cross over. But I think I am seeing light at the end of the tunnel. I have been working on the project now for about 6 weeks on and off and have written(hacked) small code snippitsd to read the microlan network for available 1-wire devices and store the device addresses in an array to be sent to the serial monitor for verification.

I have coded(hacked) Visual Basic snippits to send to arduino a read microloan command and read any returned data.

At this time, I am just working on basic communication between VB and arduino. Dallas/maxim chips are limited now to basically temp sensors, battery monitors (which have an a/d pin) and 8 channel/2 channel digital addressable switching. My vision is a "growtronix" type of system that I intend to open source. This of course has already been done....check out aquarium controllers...very similar in operation.

I am semi retired so the project has up and down times. Going work on coding tonight.

Also, I am interested in backyard grow security as well since a buddy was nearly ripped of his years worth of meds. I have been thinking about using PIR sensors to trigger a car alarm circuit and turn on the lights. Could use existing exterior sensors to turn on and off things like lights or a loud radio..

Look forward to your project.

minds_I
 
Last edited:
C

Curare Widow

In time past I have made ​​some order in the wiring.
The additional RTC I've shared. I had not dared to break me apart the board. It should be taken to ensure that the - point is connected to the quartz. The clock is accurate then.


The sensors for Temperature, RLF and the LDR for light alarm got a cable.


Later, I still want the sensors for pH, EC and get tank level.
I still need to look at some things about conversion to PH, EC values ​​me. But that will happen later.
EC, PH values i only use for the Statistic-Graph Data Screen, not to regular my Nutrients.

I have used the opportunity as a rookie from the example Numerous sketches to build something usable. The problem with this method is that the source code is very complicated and somewhat confusing.
I just have to learn step by step. That´s a full Copy Paste DISASTER.

As my Screenseaver i use the nice example code from Henning Karlsen the analog clock sketch.
... to build a nice graphic and finished with gimp is the Screenseaver



In the next days I'll even let the Arduino run a few days. If all goes well I can improve the code until next year. And if I have the equipment for the box together it can go.

...
 
C

Curare Widow

Today I want to briefly show what happens with my sensors.
Now that I've DHT11 sensors and LDR assembled my graph also writes the data to the screen.

But I have seen that I need to adjust so that the values ​​at the end just build another +1. Example at 20 °C, but the graph writes 19 °C ... but that is no problem to correct it. For me as a starter, that's a good result ...

Many hours you have to put with many new things apart, example is the gimp tool. :comfort:

Here is my Header Code
// ******************* I wrote the Happy Grow with lots of example code. So not really all of my Own Code. Has helped me the website of Henning Karlsen. *****************
// ** http://www.henningkarlsen.com/electronics
// *** And of course the famous sites of arduino.cc
//###################################################################################################################################
//###################################################################################################################################
//---------------------------------------------------------------------------------------------------------- -Library TFT Touch Screen
#include <UTouch.h>
#include <UTFT.h>
//---------------------------------------------------------------------------------------------------------- -Library for SD Card read/write
#include <UTFT_tinyFAT.h>
#include <tinyFAT.h>
#include <avr/pgmspace.h>
//---------------------------------------------------------------------------------------------------------- -Library String to Integer
#include <stdio.h>
#include <stdlib.h>
//---------------------------------------------------------------------------------------------------------- -Library Sensor for Temp/RLF & Real Time Clock
#include <dht11.h>
#include <DS1307.h>
//---------------------------------------------------------------------------------------------------------- -Library for Our Relay Shields
#include <relay8.h>
//---------------------------------------------------------------------------------------------------------- -Declare Touch Screen LCD
UTFTtf myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch myTouch(6,5,4,3,2);
//---------------------------------------------------------------------------------------------------------- -Declare RTC (Real Time Clock SCL,SDA)
DS1307 rtc(11, 12);
Time t;
Time t_temp;
//---------------------------------------------------------------------------------------------------------- -Declare Vegi Temp/RLF Sensors & Data-Pin
dht11 DHT111;
#define DHT111PIN 8
//---------------------------------------------------------------------------------------------------------- -Declare Flores Temp/RLF Sensors & Data-Pin
dht11 DHT112;
#define DHT112PIN 9
//---------------------------------------------------------------------------------------------------------- -Declare Our Relay Pins
relay8 relay(58, 59, 60, 61, 62, 65, 66, 67);
//---------------------------------------------------------------------------------------------------------- -Call Fonts
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
//################################################################################################### -$Global SD Card Error Massages
byte res;
char *verboseError(byte err){
switch (err){
case NO_ERROR:
return "No Errors found";
break;
case ERROR_NO_MORE_FILES:
return "Error No more Files";
break;
case ERROR_FILE_NOT_FOUND:
return "Error File not found";
break;
case ERROR_ANOTHER_FILE_OPEN:
return "Error another File is open";
break;
case ERROR_NO_FILE_OPEN:
return "Error no File is Open";
break;
case ERROR_WRONG_FILEMODE:
return "Error wrong Filemode";
break;
case FILE_IS_EMPTY:
return "Error File is empty";
break;
case BUFFER_OVERFLOW:
return "Buffer Overflow";
break;
case EOF:
return "END of File";
break;
case ERROR_MBR_READ_ERROR:
return "Error reading MBR";
break;
case ERROR_MBR_SIGNATURE:
return "MBR Signature error";
break;
case ERROR_MBR_INVALID_FS:
return "Unsupported filesystem";
break;
case ERROR_BOOTSEC_READ_ERROR:
return "Error reading Boot Sector";
break;
case ERROR_BOOTSEC_SIGNATURE:
return "Boot Sector Signature error";
break;
default:
return "Unknown error";
break;
}
}
//####################################################################################### -$Global Touch Coordinates Varibles
int x;
int y;
Our variables we must simply choose according to the method we can also be seen as a logic. Each has its own logic, so it is up to you.
My Setup Code
//########################################################################################################################################### -$Setup
void setup(){
//---------------------------------------------------------------------------------------------------------- -Initiate LCD Screen for Landscape
myGLCD.InitLCD(LANDSCAPE);
//---------------------------------------------------------------------------------------------------------- -Initiate Touch Screen for Landscape with HI Screen-Speed Solution
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_HI);
//---------------------------------------------------------------------------------------------------------- -Initiate SD Card for FAT16 Lib
file.setSSpin(53);
res=file.initFAT();
if (res!=NO_ERROR) {
myGLCD.print((verboseError(res)), CENTER, 150);
while (true) {
//---------------------------------------------------------------------------------------------------------- -Show Error Massage 5 sec.
delay(5000);
break;
}
}
pinMode(53, OUTPUT);
//---------------------------------------------------------------------------------------------------------- -Set RTC in run MODE
rtc.halt(false);
//---------------------------------------------------------------------------------------------------------- -Vegi light detection (LDR) Pin Definition
pinMode(vldrpin, INPUT);
//---------------------------------------------------------------------------------------------------------- -Flores light detection (LDR) Pin Definition
pinMode(fldrpin, INPUT);
//---------------------------------------------------------------------------------------------------------- -Update Vegi & Flores TEMP/RLF Sensor DATA
updatetime = millis();
//---------------------------------------------------------------------------------------------------------- -Boot Info-Text while Load Settings from SD Card
myGLCD.clrScr();
myGLCD.loadBitmap(0, 0, 320, 240, "1load.raw");
myGLCD.setFont(SmallFont);
myGLCD.print("Load Settings from SD Card...", CENTER, 180);
myGLCD.print("Please Wait...", CENTER, 200);
Load_Settings();
//---------------------------------------------------------------------------------------------------------- -Go to Login Screen
lock_screen = true;
Lock_Screen();
}
//########################################################################################################################################### -$End Setup
An here my Graph Solutions ...
void Update_Graph(){
//---------------------------------------------------------------------------------------------------------- - 0 Uhr
if (update_graph_p0 == true){
//---------------------------------------------------------------------------------------------------------- - Vegi Temp
DHT111.read(DHT111PIN);
int t1p0 = DHT111.temperature;
t1p0y1 = 0;
for (int tp0y1 = 0; tp0y1 < t1p0; tp0y1++)
t1dp0y1 = 187-((tp0y1-15)*9);
delay(30);
t1p0y1 = t1dp0y1;
//---------------------------------------------------------------------------------------------------------- - Vegi RLF
int h1p0 = DHT111.humidity;
h1p0y1 = 0;
for (int hp0y1 = 0; hp0y1 < h1p0; hp0y1++)
h1dp0y1 = 187-((hp0y1-30)*9)/2;
delay(30);
h1p0y1 = h1dp0y1;
//---------------------------------------------------------------------------------------------------------- - Flores Temp
DHT112.read(DHT112PIN);
int t2p0 = DHT112.temperature;
t2p0y1 = 0;
for (int tp0y1 = 0; tp0y1 < t2p0; tp0y1++)
t2dp0y1 = 187-((tp0y1-15)*9);
delay(30);
t2p0y1 = t2dp0y1;
//---------------------------------------------------------------------------------------------------------- - Flores RLF
int h2p0 = DHT112.humidity;
h2p0y1 = 0;
for (int hp0y1 = 0; hp0y1 < h2p0; hp0y1++)
h2dp0y1 = 187-((hp0y1-30)*9)/2;
delay(30);
h2p0y1 = h2dp0y1;

update_graph_p0 = false;
}
....
For something to be seen on the screen.
void Draw_Vegi_Temp_Graph(){
//################################################################################################################################### -Vegi Temperatur Line
myGLCD.setColor(124,252,0);
//---------------------------------------------------------------------------------------------------------- - Draw Line at 0.00 Uhr
myGLCD.drawLine(21,t1p0y1,33,t1p1y1);
//---------------------------------------------------------------------------------------------------------- - Draw Line at 1.00 Uhr
...
I have the next few weeks no time to play around with Arduino. I hope there is more time to play again soon
 
C

Curare Widow

I have problems during the test run with the RTC and Arduino.
The reasons were that I have built the complete power supply via USB. I used a cheap mobile phone charger with USB output during the test run under full load. The Arduino is switched off for safety reasons at 500mA.

I have to use the VIN-PIN if I want to use an external power source without USB or power adapter connector.

The test run is a simulation for the flowering phase. The sensors work well.



Ok, next step is the installation of an external power source. I have found a cheap and suitable here.
 

minds_I

Active member
Veteran
Hello all,

Looking good.

I am interfacing my arduino with a windows app that is so far coded in C#. I abandoned VB and C++ for C#.

So far I have communication between the maxim 1-wire devices and the arduino and between the arduino and the windows app. I am able to read multiple DS18B20/18S20 temp sensors, DS2438 battery monitor used for A/D conversion for the humidity, CO2, Boolean devices such as flood, water level and barometric pressure voltage readings and the ds2413 open drain switches.

Thus far I have a working form that displays temperature and humidity. I also have functional control from the app of the ds2413 switches.

I am able to communicate without errors however, there is little int he way of error handling which needs to be addressed.

I have coded a text sending routine through smtp...need on how to control from a remote device (later). Also, I have data logging routine that is functional but still far from ready. Still many variables yet unknown.

Here are some screen shots of a work in progress.

I have C# programming questions that I need answers to. Google is great but sometimes is not enough.

picture.php


picture.php

Arduino code thus far...its messy at points and is being worked on.




#include <OneWire.h>

// Dallas/Maxim available 1-wire dievce addresses
//10 C0 F0 2 1 8 0 18 .... DS18S20
//10 74 91 2 1 8 0 1F .... DS18S20
//10 EA B3 2 1 8 0 C6 .... DS18S20
//1E 74 62 29 0 0 0 B1 .... DS2438 battery montor (a/d converter)
//1E AA 66 29 0 0 0 79 .... DS2438 battery montor (a/d converter)
//1E DA 63 29 0 0 0 33 .... DS2438 battery montor (a/d converter)
//3A 30 86 7 0 0 0 A3 ..... DS2413 programmable io deivce (open drain swith)
//3A 66 3B 17 0 0 0 A4 ..... DS2413 programmable io deivce (open drain swith)
//3A A1 24 F 0 0 0 89 ..... DS2413 programmable io deivce (open drain swith)
// identification of dallas/maxim 1-wire devices on microlan network
#include <OneWire.h>
// declare global variables
OneWire ds(10); // on pin 10
int ledpin = 13; // on board led pin
int deviceCount=0; // initialize device counter
int stopcheck=0; // device search flag
char cmd_input; // input command variable ASCII 1 to 10
byte deviceaddr[32][8]; // 1-wire device address index array of active devices on microlan
byte data[9]; // data array ( 9 byte) typical lenght of data from ds devices
byte addr[8]; // device address array 8 byte array
byte addr1[8];
int flag=0;
int i; // indexing variable
int j; // indexing variable

byte present = 0;
byte type_s;
byte tempdata[12];
byte voltdata[12];
byte a2ddata[12];
float averagetempsum;
float celsius;
float fahrenheit;
float voltage;
unsigned int rawtemp;
unsigned int raw1;
byte confirmationByte;
byte piopinStatus;

// ********************************** setup ****************************************************************
// configure serial port baud rate
void setup(void)
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT); // set on board led pin as output
digitalWrite(ledpin,LOW);
}
// ******************************* Main Loop *****************************************************
void loop(void)
{

// declare local variables

if (flag = 0)
{
deviceCount = 0; // zero device counter
microlan_search(); // call search microlan
flag =1;

}

if (Serial.available()) // Check to see if at least one character is available
{
char cmd_input = Serial.read(); // read single byte from serial buffer

if(cmd_input >= '1' && cmd_input <= '9') // is this an ascii digit between 0 and 9?
{
//Serial.print("verified command inputted ");
//Serial.print(cmd_input);

if(cmd_input == '1') // preform 1-wire device search on microlan
{
deviceCount = 0; // zero device counter
microlan_search(); // call search microlan
}
if(cmd_input == '2') // preform device dump
{
deviceindexdump(); // call device index dump to screen
}
if(cmd_input =='3') // turn on on-board led for 5 seconds
{
ledblink(5);
}
if(cmd_input =='4') // read temps on all 1-wire temperature devices
{
readTempds18s20();
}
if(cmd_input =='5') // close ds2413 open drain digital switches (bit toggling)
{
closeSwitchds2413();
}
if(cmd_input =='6') // open ds2413 open drain digital switches (bit toggling)
{
openSwitchds2413();
}
if(cmd_input =='7') // read voltage from ds2438 dedicated 10 bit a/d converter
{
readVoltageds2438();
}
if(cmd_input == '8') // read ds2438 device switch status
{
readSwitchStatus();
}
if(cmd_input == '9') // read ds2438 device on board temperature sensor
{
readTempds2438();
}
}
}
}





//************** CASE 1 Microlan device search Subroutine ASCII '1' *************************
//
void microlan_search(void)
{
// declare local variables
// Query microlan for available divices
while(ds.search(addr))
{
if (flag =0)
{
// addr1=addr;
flag = 1;
}
deviceCount = deviceCount+1; //increment device counter
for( i = 0; i < 8; i++)
{
deviceaddr[deviceCount-1]=addr; // Store detected 1-wire device address to device index address array
}
}
if ( OneWire::crc8( addr, 7) != addr[7])
{
Serial.print("CRC - DEVICE IDENTIFICATION ERROR \n");
return;
}
ds.reset_search();
return;
}


// ******************************** CASE 2 device index screen dump ASCII '2' subroutine **********************************

void deviceindexdump(void)
{
// ************************************** declare subroutine local variables *********************************
int j; // counter index
int i; // counter index
//Serial.print("\n\ndevice index contents\n");
// write to serial buffer in decimal the number of detected 1-wire devices on microlan
//Serial.print(deviceCount, HEX); // print number of devices available
// print to serial buffer the device address index array
Serial.println(deviceCount);
for (j = 0; j < deviceCount; j++)
{
//Serial.print("device ");
//Serial.print(j+1);
//Serial.print("address = ");
// write to serial buffer the number of detected devices and each 1-wire device address in hex
for (i=0;i<8;i++)
{
// if (deviceaddr[j] < 16)
// {
// Serial.print("0");
// }
Serial.println(deviceaddr[j], DEC);
if (i < 7)
{
//Serial.print(",");
}
}
//Serial.print("\n");
}
//deviceCount=0; // reset device counter
return;
}

//************************ CASE 3 subroutine ASCII '3' ******************************
// blink the LED with the on and off times determined by blinkRate
void ledblink(int sleep)
{
digitalWrite(ledpin,HIGH);
delay(sleep*1000); // delay depends on blinkrate value
digitalWrite(ledpin,LOW);
return;
}


//************************CASE 4 get temp reading ds18s20 subroutine ASCII '4' ******************************

void readTempds18s20(void) //addr, int sleep)
{
averagetempsum = 0; // declare local variables
unsigned int raw;
unsigned int raw1;
// TAKE 10 SAMPLES AND AVERAGE THE RESULTS
for ( j = 0; j<1; j++)
{
present=0; //set device present flag to 0 (null)
raw=0;
//unsigned int raw
// Dallas/maxim protocal command sequence for device to DS18S20 to take temperature sample
// begin DS18s20 initialization

ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[0]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x44,1); // issue temperature conversion command (44h) with parasite power (Data line held high(1))on at the end
delay(10); // Wait for device to complete temperature conversion command

present = ds.reset();//Reset the microlan bus...
ds.select(deviceaddr[0]); // Select current 1-wire device being polled (issue Match Rom command 55h)
ds.write(0xBE,0); // issues Read Scratchpad command

// Serial.print(" Temp Data = ");
// Serial.print(" ");

// read 9 bytes of data from scratchpad
for ( i = 0; i < 9; i++)
{
tempdata = ds.read();
// Serial.print(tempdata, DEC);
// Serial.print(",");
// Serial.print(tempdata, HEX);
// Serial.print(" ");
}
//
// check CRC for data error
if ( (tempdata[7] == 0x10) && (OneWire::crc8( addr, 8) == addr[8]) )
//convert the data to temperature 12 bit resolution
{
unsigned int raw = (tempdata[1] << 8) | tempdata[0];// bit shift byte1 and "or" it with byte0
raw = raw << 3;
raw = (raw & 0xFFF0) + 12 - tempdata[6];
averagetempsum = averagetempsum+((float)raw / 16.0);
}

else
{
Serial.print("\n error reading data on ds18s20 \n");
}
}
// output to serial port
celsius=averagetempsum;
Serial.println(celsius, 2);
return;
}

//************************CASE 5 close ds2413 pio pin 0 close ds2413 pio pin 1 ASCII '4' ******************************

void closeSwitchds2413(void)
{
// declare local variables

ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[1]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x5A,0);

ds.write(0xFC,0); // Write new PIO output state (close both pins)
ds.write(0x03,0); // Write inverted new PIO output state (both on)
confirmationByte = ds.read();
piopinStatus = ds.read();
ds.reset();

Serial.println(confirmationByte);
//Serial.print(" PIO pin status");
Serial.println(piopinStatus);

return;
}
//************************CASE 6 open ds2413 pio pin 0 close ds2413 pio pin 1 ASCII '4' ******************************

void openSwitchds2413(void)
{
byte confirmationByte ;
byte piopinStatus;
ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[1]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x5A,0); // issue "PIO Access Write" command

ds.write(0xFF,0); // Write new PIO output state (open both pins)
ds.write(0x00,0); // Write inverted new PIO output state
confirmationByte = ds.read();
piopinStatus = ds.read();
// error checking to be preformed here
// ds.write(0xFD,0); // Write new PIO output state (open pin 1 only)
// ds.write(0x02,0); // Write inverted new PIO output state
// confirmationByte = ds.read();
// piopinStatus = ds.read();


// ds.write(0xFE,0); // Write new PIO output state (open pin 0 only)
// ds.write(0x01,0); // Write inverted new PIO output state
// confirmationByte = ds.read();
// piopinStatus = ds.read();
ds.reset(); //Reset the microlan bus...
Serial.println(confirmationByte);
Serial.println(piopinStatus);

return;
}


//************************CASE 7 read a/d voltage conversion from DS2438 ASCII '7' ******************************

void readVoltageds2438(void)

{
//ds2438 memory configuration
ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x4E,0); // issue memory configuration command (4Eh)
ds.write(0x00,0); // issue memory configuration command (00h) page 00h
ds.write(0x00,0); // set Vad conversion
////////////////////////////////////////////
present = ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0xB4,0); // issue voltage conversion command (B4h) with parasite power (Data line held high(1))on at the end
delay(10); // Wait 10 ms for device to complete command
// Dallas/maxim protocal sequence for device to DS2438 to issue Recall Memory page 00h command (B8h, ooh)
present = ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0xB8,0); // issue Recall memory page 00h (B8h) with parasite power (Data line held high(1))on at the end
ds.write(0x00,0); //
// Wait for device to complete command
///////////////////////////////////////
present = ds.reset();//Reset the microlan bus...
ds.select(deviceaddr[2]); // Select current 1-wire device being polled (issue Match Rom command 55h)
ds.write(0xBE),0; // issues Read Scratchpad command
ds.write(0x00),0; // issues Read Scratchpad command
// Serial.print(" Voltage Data = ");


// read 9 bytes of data from scratchpad
for ( i = 0; i < 9; i++)
{
voltdata = ds.read();
// Serial.print(voltdata, HEX);
// Serial.print(" ");
}

// Serial.print(" CRC=");
// Serial.print(OneWire::crc8(voltdata, 8), HEX);
voltage = voltdata[4] * 256 + voltdata[3];
//Serial.print("\n voltage equals = ");
Serial.println (voltage/100,2);
delay(1000);
present = ds.reset();//Reset the microlan bus...
return;
}
///////////// ds2413 switch pin status check/////////////////////////



//////////////////////////////////////////////////////////////



void readSwitchStatus(void)
{
// byte confirmationByte ;
// byte piopinStatus;
ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[1]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0xF5,0);
confirmationByte = ds.read();
piopinStatus = ds.read();
ds.reset(); //Reset the microlan bus...
Serial.println(piopinStatus);
return;
}

//************************CASE 9 read temperature conversion from DS2438 ASCII '9' *******

void readTempds2438(void)

{
present=0; //set device present flag to 0 (null)
//raw=0;
averagetempsum = 0; // declare local variables
unsigned int rawTemp;
unsigned int raw1;
// TAKE 10 SAMPLES AND AVERAGE THE RESULTS
for ( j = 0; j<1; j++)
{
//ds2438 memory configuration
ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x4E,0); // issue memory configuration command (4Eh)
ds.write(0x00,0); // issue memory configuration command (00h) page 00h
ds.write(0x00,0); //
////////////////////////////////////////////
present = ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0x44,0); // issue temperature conversion command (44h) with parasite power (Data line held high(1))on at the end

//present = ds.reset(); //Reset the microlan bus...
//ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
//ds.write(0xB4,0); // issue voltage conversion command (B4h) with parasite power (Data line held high(1))on at the end
delay(1000); // Wait for device to complete command
// Dallas/maxim protocal sequence for device to DS2438 to issue Recall Memory page 00h command (B8h, ooh)
present = ds.reset(); //Reset the microlan bus...
ds.select(deviceaddr[2]); // Select 1-wire device to be polled (issue Match Rom command 55h)
ds.write(0xB8,0); // issue Recall memory page 00h (B8h) with parasite power (Data line held high(1))on at the end
ds.write(0x00,0); //
// Wait for device to complete command
///////////////////////////////////////
present = ds.reset();//Reset the microlan bus...
ds.select(deviceaddr[2]); // Select current 1-wire device being polled (issue Match Rom command 55h)
ds.write(0xBE),0; // issues Read Scratchpad command
ds.write(0x00),0; // issues Read Scratchpad command
// Serial.print(" Voltage Data = ");


// read 9 bytes of data from scratchpad
for ( i = 0; i < 9; i++)
{
tempdata = ds.read();
// Serial.print(tempdata, HEX);
// Serial.print(" ");
}
present = ds.reset();//Reset the microlan bus...
// Serial.print(" CRC=");
// Serial.print(OneWire::crc8(voltdata, 8), HEX);

//average calcs
rawTemp = rawTemp + tempdata[2] * 256 + tempdata[1];
}
celsius = rawtemp/10;
Serial.println (celsius/256,2);
return;
}
...


Here is the C# coding. It is very messy but I am still learning C#.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.IO;
using System.Threading;
using System.Net;
using System.Net.Mail;
//using System.StreamReader;
//using System.StreamWriter;
//using System.StreamReader;
namespace Arduino1wireinterface
{
public partial class Form1 : Form
{
double tempCel; // Temperature variable (celsius)
double Tfahr; // Temperature variable (faherhiet)
double Tdp;
double gamma;
double VPD;//
double SVP;
double tempMax = 0; // maximum temperature variable
double tempMin = 100; // minimum temperature variable
double RHMax = 0; // relative humidity maximum variable
double RHMin = 100; // relative humidity minimum variable
double voltage; // declare ds2438 voltage input variable
double RH; // relative humidity variable
float a = 0.00003f;// declare variables for humidity dew point calculations
float b = 0.0281f;//
double c = 0.82d;//
float aa = 6.1121f; // units are millibars
float bb = 18.678f;
float cc = 257.14f; // units are celsius
float dd = 243.5f; // units are celsius
int switchConfirmation; // ds2413 Command confirmation variable
int deviceCount; // count of devices of available on microlan
int switchStatus; // ds 2413 switch staus variable
int i; /// loop index
int j; /// loop index
String serDataRecvd; // declare serial port data string buffer
SerialPort serialPort1 = new SerialPort(); // declare serialPort1 as new serial port using Systems io class as template???
int[,] deviceAddress = new int[32, 8]; // available 1 wire device addresses array
int[,] deviceCurrent = new int[1, 8]; // current device address
//var timestamp; // declare timestamp variable
public Form1()
{
InitializeComponent();




}
private void Form1_Load(object sender, EventArgs e)
{
/// clear serial port buffers
///
button2.Enabled = false;
this.timer1.Enabled = false; // turn timer event off for serial port initialization

//set serial port settings



serialPort1 = new SerialPort("COM3");
serialPort1.BaudRate = 9600;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DataBits = 8;
serialPort1.Handshake = Handshake.None;
serialPort1.Open();

//serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); // declare serial data received event before opening serial port
// initiate microlan and retrive available 1 wire device addresses and store in deviceAddress[,] array
serialPort1.Write("1");
serialPort1.Write("2");

//// get number of devices available on microlan deviceCount
serDataRecvd = serialPort1.ReadLine();
deviceCount = Convert.ToInt16(serDataRecvd);

for (i = 0; i < deviceCount; i++)
{
for (j = 0; j < 8; j++)
{
//serDataRecvd = serialPort1.ReadLine();

deviceAddress[i, j] = Convert.ToInt16(serialPort1.ReadLine());
}
}
//
this.timer1.Enabled = true; // turn timer event on
//

button2_Click(this, new EventArgs());

}






//private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
//{
// //serdatrecvd += serialPort1.ReadExisting().ToString();
// //pdata(serdatrecvd);

// serDataRecvd = serDataRecvd + serialPort1.ReadLine();
// pdata(serDataRecvd); /// this calls the class pdata
//}

//delegate void SetTextCallback(string text);


//private void pdata(string data)
//{
// // InvokeRequired required compares the thread ID of the
// // calling thread to the thread ID of the creating thread.
// // If these threads are different, it returns true.
// if (this.label1.InvokeRequired)
// {
// SetTextCallback d = new SetTextCallback(pdata);
// this.Invoke(d, new object[] { data });
// }
// else
// {if (data.Length >= 1)
// {

// this.label1.Text = "";
// this.label1.Text = data;
// }
// }
//}
//private void button1_Click(object sender, System.EventArgs e)
//{
// // declare method vaiables
// decimal celsius;
// decimal Tfahr;
// //serialPort1.Write("1");
// serialPort1.Write("4");
// serDataRecvd = serialPort1.ReadLine();
// celsius = Convert.ToDecimal(serDataRecvd);
// Tfahr =9*celsius /5 +32;
// //this.label1.Text = serDataRecvd;
// this.label1.Text = celsius.ToString()+"C";
// this.label2.Text = Tfahr.ToString()+"*F";
//}



private void timer1_Tick_1(object sender, EventArgs e)
{
////////////////////////////////////////////////////// get temp routine ////////////////////////
// declare method vaiables
var timestamp = DateTime.Now.ToString("MM/dd HH:mm:ss"); // sample time stamp
serialPort1.Write("4"); // send cmd "4" to arduino
serDataRecvd = serialPort1.ReadLine(); // get data off serial port
tempCel = Convert.ToDouble(serDataRecvd);
Tfahr = 9 * tempCel / 5 + 32;
label1.Text = tempCel.ToString("00.0") + "C";
label2.Text = Tfahr.ToString("00.0") + "*F";
label3.Text = "Current Date/Time " + timestamp.ToString();


if (pictureBox3.Image != Image.FromFile("G:/STEADYARROW.png"))
{
pictureBox3.Image = Image.FromFile("G:/STEADYARROW.png");
}



// min/max comparison routine
if (tempCel > tempMax)
{
tempMax = tempCel;
label4.Text = "Max. " + tempMax.ToString("00.0") + "C " + timestamp.ToString();
pictureBox3.Image = Image.FromFile("G:/UPARROW.png");
}
if (tempCel < tempMin)
{
tempMin = tempCel;
label5.Text = "Min. " + tempMin.ToString("00.0") + "C " + timestamp.ToString();
pictureBox3.Image = Image.FromFile("G:/DOWNARROW.png");
}

// data logger routine writes to sample timestamp and sample data to end of file //
//StreamWriter dataLoggerTemp = new StreamWriter(@"G:\templog.csv", true);
//dataLoggerTemp.Write(timestamp.ToString()); // write current temperature sample timestamp
//dataLoggerTemp.Write(",");
//dataLoggerTemp.Write(tempCel.ToString()); // write current temperature data to file
//dataLoggerTemp.Write("\r\n");
//dataLoggerTemp.Flush(); // clear buffer
//dataLoggerTemp.Close(); // close file

////////////////////////////////////////// get voltage sensor data


//// humidity routine beta
serialPort1.Write("7"); // send cmd "7" to arduino
serDataRecvd = serialPort1.ReadLine(); // read voltage string
voltage = Convert.ToDouble(serDataRecvd);// convert to decimal
RH = ((-b + Math.Sqrt(Math.Pow(b, 2) - 4 * a * (c - Convert.ToSingle(voltage)))) / (2 * a));
// Vapor pressure calcs
SVP = .61078 * Math.Exp(((17.27 * tempCel) / (tempCel + 237.3))); // calculate Saturation vapor pressure
VPD = 10 * SVP * (1 - RH / 100); // calculate Vapor Pressure Deficit

gamma = Math.Log((RH / 100) * Math.Exp((bb - tempCel / dd) * (tempCel / (cc + tempCel))));
Tdp = cc * gamma / (bb - gamma); // calculate Dew Point Temperature


label6.Text = RH.ToString("0.0") + " %RH";// output to screen
label9.Text = "VPD " + VPD.ToString("0.00") + " kPa";// output to screen
label10.Text = "Dew Point " + Tdp.ToString("0.00") + " C";
// trend arrow image handling
if (pictureBox1.Image != Image.FromFile("G:/STEADYARROW.png"))
{
pictureBox1.Image = Image.FromFile("G:/STEADYARROW.png");
}

// min/max function for max/min indicators
if (RH > RHMax)
{
RHMax = RH;
label7.Text = "Max. " + RHMax.ToString("0.0") + " %RH " + timestamp.ToString();
pictureBox1.Image = Image.FromFile("G:/UPARROW.png");
}
if (RH < RHMin)
{
RHMin = RH;
label8.Text = "Min. " + RHMin.ToString("0.0") + " %RH " + timestamp.ToString();
pictureBox1.Image = Image.FromFile("G:/DOWNARROW.png");
}



}
//////////////////////////////////// close ds2413 digital switch ////////////
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write("5"); // send cmd "5" to arduino
serDataRecvd = serialPort1.ReadLine(); // get get confirmation vyte off serial port
switchConfirmation = Convert.ToInt16(serDataRecvd); //
serDataRecvd = serialPort1.ReadLine(); // get status byte off serial port
switchStatus = Convert.ToInt16(serDataRecvd);
//if ((switchConfirmation = 170) && (switchStatus = 120))
//{
button1.Enabled = false;
button2.Enabled = true;
pictureBox2.Image = Image.FromFile("G:/switchON.jpg");

return;
}
//////////////////////////////////// open ds2413 digital tswitch //////////// ( this, new EventArgs())
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("6"); // send cmd "6" to arduino
serDataRecvd = serialPort1.ReadLine(); // get get confirmation vyte off serial port
switchConfirmation = Convert.ToInt16(serDataRecvd); //
serDataRecvd = serialPort1.ReadLine(); // get status byte off serial port
switchStatus = Convert.ToInt16(serDataRecvd);

//if ((switchConfirmation = 170) && (switchStatus = 120))
// Need error handling
button1.Enabled = true;
button2.Enabled = false;
pictureBox2.Image = Image.FromFile("G:/switchOFF.jpg");
return;
}

private void pictureBox2_Click(object sender, EventArgs e)
{
serialPort1.Write("8"); // send cmd "8" to arduino to retrieve ds2413 switch status
//serDataRecvd = serialPort1.ReadLine(); // get get confirmation vyte off serial port
switchStatus = Convert.ToInt16(serialPort1.ReadLine());
if (switchStatus == 15)
{
button1_Click(this, new EventArgs());
return;
}
if (switchStatus == 30)
{
button1_Click(this, new EventArgs());
return;
}
if (switchStatus == 75)
{
button1_Click(this, new EventArgs());
return;
}
if (switchStatus == 240)
{
button2_Click(this, new EventArgs());
return;
}

return;
}
// display available device address to window
private void button3_Click(object sender, EventArgs e)
{
for (i = 0; i < deviceCount; i++)
{
for (j = 0; j < 8; j++)
{
//serDataRecvd = serialPort1.ReadLine();

textBox1.Text = textBox1.Text + deviceAddress[i, j].ToString();
if (j < 7)
{
textBox1.Text = textBox1.Text + ",";
}

}
textBox1.Text = textBox1.Text + "\n";
}

}

private void button4_Click(object sender, EventArgs e)
{
tempMax = 0;
tempMin = 100;
}

private void button5_Click(object sender, EventArgs e)
{
RHMax = 0;
RHMin = 100;
}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{

}

private void fileToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
{

}






private void sendTestTextToolStripMenuItem_Click(object sender, EventArgs e)
// SEND TEXT MESSAGE TO ASSIGNED EMAIL ADDRESS
{
SmtpClient SmtpServer = new SmtpClient("smtp.att.yahoo.com", 587);
try
{
SmtpServer.EnableSsl = true;
//SmtpServer.Timeout = 100000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new NetworkCredential("[email protected]", "mine");
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
mail.Subject = "test Subject";
mail.Body = "It works...move on";
//Attachment attachment = null;
//mail.Attachments.Add(attachment);

SmtpServer.Send(mail);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}

private void label1_Click(object sender, EventArgs e)
{

}

private void button7_Click(object sender, EventArgs e)
{

}

private void button6_Click(object sender, EventArgs e)
{

}


}
}



// data logger routine writes to sample timestamp and sample data to end of file //
// StreamWriter dataLoggerTemp = new StreamWriter(@"G:\templog.csv", true);
// dataLoggerTemp.Write(timestamp.ToString()); // write current temperature sample timestamp
// dataLoggerTemp.Write(",");
// dataLoggerTemp.Write(celsius.ToString()); // write current temperature data to file
// dataLoggerTemp.Write("\r\n");
// dataLoggerTemp.Flush(); // clear buffer
// dataLoggerTemp.Close(); // close file

...
 
Last edited:

minds_I

Active member
Veteran
Hello all,

It can be seen that I need more guidance with regard to my programming skilz

It is a hobby project after all.

Any suggestions as to improving the project are welcome.

minds_I
 

McKush

Éirinn go Brách
ICMag Donor
Veteran
subscribed.

I have a number of arduino's lying around that I have thought about using to monitor and control my environment & feeding in my grow area.

Once my room is complete I may use this info to jumpstart my own project so thanks for sharing all!
 
C

Curare Widow

Wonderful, that's nice. Nice to see some action coming into the project.

I'm going tonight to install the new power supply.
I have revised my source code a bit.

I'll make tonight a small package done. Complete with SD CARD files. I hope there is some feedback because I just no possibility to make accurate tests.

I examine now exactly how I could connect the RTC. SQW pin, etc.
 
C

Curare Widow

I have all the files from my SainSmart project. (12MB)
More I can not do. I'm even beginners. Maybe someone has fun on my project. If not, it is I actually do not care.
But have no rights to Upload the file here!

Your hardware must of course match the project hardware.
Pictures of the project are somewhere at the beginning of this article.

Search Something ....

The User @minds_I has flooded my article with his project. My project is something completely different! Maybe he does not know how to build an own article? I do not know ...

Update later ...
 

minds_I

Active member
Veteran
Hello all,

Sorry dude, I will take it down if you want...did not mean to crash your thread...thought I was helping in exchange I might get some help coding.

minds_I
 
C

Curare Widow

THIS THREAD ARE CLOSED =>
 
Last edited by a moderator:
Status
Not open for further replies.

Latest posts

Latest posts

Top