Sciencemadness Discussion Board

Anybody interested in custom libraries/programs for Arduino?

andymadman - 7-1-2015 at 21:55

I've been playing around with the Arduino CPP-like language for a while now, and have really been enjoying it. I was wondering if anybody was interested in having custom libraries/programs written for them. I've written a few libraries so far, and the most recent few have turned out extremely well, but I've run out of shields and displays to write code for. If anybody has something they'd like coded or ideas for programs to keep me entertained, I'd be greatly appreciative.

Chemosynthesis - 8-1-2015 at 04:13

That sounds extremely generous of you. Definitely interested in how this turns out.

ahill - 8-1-2015 at 19:29

I'd be especially interested in experience (and notable successes or failures) you or others have had using an arduino as part of chemical experiments or processes.

I have had fantasies of using one to measure and control temperature, pH, and current in a (per)chlorate cell, or measure temperature of a still-head etc etc - but have never got around to actually implementing anything.

If you are just looking for an idea - write something to log the temperature taken from one or more strategic points on a distillation rig to a CSV file during an entire distillation.

gardul - 8-1-2015 at 19:36

Quote: Originally posted by ahill  
I'd be especially interested in experience (and notable successes or failures) you or others have had using an arduino as part of chemical experiments or processes.

I have had fantasies of using one to measure and control temperature, pH, and current in a (per)chlorate cell, or measure temperature of a still-head etc etc - but have never got around to actually implementing anything.

If you are just looking for an idea - write something to log the temperature taken from one or more strategic points on a distillation rig to a CSV file during an entire distillation.


I use one to control stiring on a little servo motor.. XD a ver very lame use of one but it works for the most part.

IrC - 8-1-2015 at 23:59

If you will search a year or two ago there were a couple long threads on this subject with a fair amount of discussion on the topic of using Atmel, Picaxe, Arduino, and Raspberry Pi for various monitoring and controlling in chemical experiments.

andymadman - 9-1-2015 at 16:46

Quote: Originally posted by ahill  
I'd be especially interested in experience (and notable successes or failures) you or others have had using an arduino as part of chemical experiments or processes.

I have had fantasies of using one to measure and control temperature, pH, and current in a (per)chlorate cell, or measure temperature of a still-head etc etc - but have never got around to actually implementing anything.

If you are just looking for an idea - write something to log the temperature taken from one or more strategic points on a distillation rig to a CSV file during an entire distillation.


Should I write it for a 10k SS thermometer? I've never used a pH meter in anything but a lab, and I don't own any of my own. As for the temp control, I could write the code for a mosfet H-bridge driving a peltier cell and have it heat or cool based on the temperature read by the thermometer whenever the temperatures fell outside a pre-determined range. Adding code for an IIC or UART driven 2x16 or 4x20 Hitachi-based LCD wouldn't be a problem. For the logging I could have it save on a second, minute, or hour basis to a .txt file using an Arduino Uno SD card shield. I don't know anything about the architecture of a CSV file, but I'll research it, and if it seems do-able I'd add it. I've never really done much combining Arduino and chemistry, although separately I've done plenty of each that it's not hard to imagine the possibilities that come with combining the two. Forgive me if this takes me a little while, I'm 17, still in High School and finals are coming up in a week so I might get to it around the 16th.

andymadman - 9-1-2015 at 21:52

So here's what I got so far:
Spent about 5 hours on it today, I mostly just set up the temperature reading and conversion and figured out an error report and debug system. ~300 line of code so far, with comments it's about 400 lines.

Code:
/*Arduino Temperature Data Logging Program, Wittten by Andrew Spangler (andymadman), KG7BHQ for you hams out there, I would recommend the Seeed Studio SD Card Shield V3.X (any V3 will work) for the SD card interface, although you can probably change the code to work with other SD shields/devices. For the LCD, any I2C,(IIC so no one will be pedantic about it) backpack will work, and for the LCD try and get a hitachi driver 20x4 character LCD as thery have more than double the usuable printing space and displaying data is a lot easier than it is on a 16x2. I've written this program to work with both 16x2 and 20x4 LCD displays. */ /* _________________ _________ \ / | | \ \ / | | | \ /\ / | | / \ / \ / | |________/ \ / \ / | | \ / \ / | | \/ \/ ________^_______ | */ #include "SdFat.h" /*include SdFat library, not shipped with program see readme for downloads and hardware information*/ #include "LiquidCrystal.h" //include IIC LiquidCrystal library, not shipped with program. LiquidCrystal lcd(0); /*create instance of LiquidCrystal called "lcd" with IIC address 0, change if IIC address on IIC backpack is different, see (not yet existant) readme for downloads and hardware information*/ //Human controlled variables: int HTT; /*high temperature threshhold, the maximum temperature before the Arduino begins cooling with the peltier cell */ int LTT; /*Low temperature threshhold, the maximum temperature before the Arduino begins heating with the peltier cell */ int MTT; /*Mid temperature threshhold, the temperature Arduino attempts to achieve with the peltier cell */ int rTime = ""; // time between log readings int BPin1 = ""; //Pin one for the peltier cell h-bridge int BPin2 = ""; //Pin two for the peltier cell h-bridge int TN = ""; /*The number of thermometers to be connected to the Arduino, 0-3, thermometers must be used in order, eg you can't read from thermometers 1 and 3 if you specify there being 1 thermometer, you must read from thermometer 1, if you specify there being 2 thermometers, you must read from thermometers 1 and 2, etcetera */ int TR0 = ""; //Thermometer #1 read pin, must be analog, Called "A" on LCD to save space //Thermometers coded for TMP36 Temperature Sensors, available at http://www.adafruit.com/products/165 int TR1 = ""; //Thermometer #2 read pin, must be analog, Called "B" on LCD int TR2 = ""; //Thermometer #3 read pin, must be analog, Called "C" on LCD int TM0; //Storage variable for Thermometer #1 int TM1; //Storage variable for Thermometer #2 int TM2; //Storage variable for Thermometer #3 boolean tUnit = false; //boolean true to convert to fahrenheit, default celcius. int ProtestPin = 13; /*Pin to pwm output value 127 in the case of an error, use to blink an led, run a quartz squeeler, or power a buzzer, by default onboard LED */ int lcdState = ""; // 0 if no lcd, 1 if IIC lcd, different versions to come for UART and Serial LCD. boolean lcdType = ""; //true if 20x4, false if 16x2 boolean SerState = true; //Enable Serial debugging, False if not wanted. //Program controlled variables, humans shouldn't touch these: int lcdL; //initialize lcdL (lcd Length), but don't define it int lcdH; //initialize lcdH (lcd Height), but don't define it boolean lcdStatus = false; //Status of whether or not an lcd is connected. boolean ErrStatus = false; //Status of whether or not an error has occured /* Error Number Human Lookup Table: Error #: Description of error: Possible cause: 0 | Default | Means something triggered the ErrStatus boolean without setting an error number, should never see. 1 | LCD | Numbers in Human LCD Fields invalid 2 | Thermometer (General) | Numbers in Human Thermometer Fields invalid, usually too many thermometers. Check if TN is too high. 3 | Thermometer (HIGH/LOW) | analogRead values yeild results of <32 or >992, means thermometer is probably not connected properly. 4 | SD Card (General) | SD card not found, SD card removed 5 | SD Card (Read) | SD card is corrupt, SD card is not in FAT16 or FAT32 format 6 | SD Card (Write) | SD card is in read-only (little switch is "locked") 7 | SD Card (Memory) | SD card is corrupt, SD card is full 8 | Available, but not used | Shouldn't turn up unless you change the program and add it yourself 9 | Available, but not used | Shouldn't turn up unless you change the program and add it yourself */ boolean er1 = false; // \ boolean er2 = false; // \ boolean er3 = false; // \ boolean er4 = false; // \ boolean er5 = false; // }--- booleans used for computing the number of errors, false by default. boolean er6 = false; // / Changing these may result in false error messages. boolean er7 = false; // / boolean er8 = false; // / boolean er9 = false; // _/ String erStr = ""; //These parenthesis don't need to be changed. IF CHANGED THEY MAY SCREW UP ERROR MESSAGES char unit; void setup(){ if (SerState == true){ Serial.begin(9600); //begin serial communication over USB } if (tUnit == true) { unit = "F" } else { unit = "C" } if (lcdState > 0) { //if an lcd is of any state other than nil lcdStatus = true; //change boolean lcdStatus to true, by default //lcdState is false so if lcdState is 0, do nothing switch (lcdType) { //Switch based on the Human boolean that says whether the LCD is 20x4 or 16x2 case 0: //If the boolean is false, the LCD is 16x2 lcdL = 16; //Set the LCD's length to 16 lcdH = 2; //Set the LCD's height to 2 break; case 1: //If the boolean is true, the LCD is 20x4 lcdL = 20; //Set the LCD's length to 20 lcdH = 4; //Set the LCD's height to 4 break; case >1: er1 = true; break; } lcd.begin(lcdL,lcdH); //Initializes the LCD, using the variable just set lcd.setBacklight(High); //turn the backlight on } pinMode(BPin1 ,OUTPUT); //h-bridge pins 1 and 2 are set to output pinMode(BPin2 ,OUTPUT); pinMode(ProtestPin, OUTPUT): //Set protest pinMode to output switch (TN) { /*this just eliminates a bunch of "if" statements regarding the setup of the thermometers */ case 0: //No thermometer, don't setup anything break; case 1: //1 Thermometer, setup thermometer 0 pinMode(TRP0, INPUT); break; case 2: //2 Thermometers, setup thermometers 0 and 1 pinMode(TRP0, INPUT); pinMode(TRP1, INPUT); break; case 3: //3 Thermometers, setup thermometers 0, 1, and 2 pinMode(TRP0, INPUT); pinMode(TRP1, INPUT); pinMode(TRP2, INPUT); break; case >= 4: er1 = true; break; } void loop() { protest(); if (TN>0) { tempUpdate(); lcdTempUpdate(); if (SerState == true) { SerTemp(); } } } void protest() { erUpdate(); if ((erStr.length)>0){ //if the error string (erStr) has any characters at all, go through the output. analogWrite(ProtestPin, 127); //Turn on the ProtestPin if (SerState == true){ Serial.println("") Serial.println("") Serial.println(millis()/1000); Serial.println(erStr); Serial.println("") Serial.println("") } if (lcdStatus == true){ //If there is an lcd lcd.setBacklight(LOW); //turn backlight off delay(100); //wait 1/5th of a second lcd.setBacklight(HIGH); //turn the backlight on switch(lcdType) { case 0: lcd.setCursor(1,(lcdW-(1+ (erStr.length))); //here we're calculating the number of characters //by finding the character length of the string //erStr and adding it to the 1 needed to print "ER" //minus the one caused by the memory addresses in //the IIC counting from zero. lcd.print("ER"); lcd.print(erStr); //don't ever do this kids ;) this is the lazy way } //of writing code (although a little easier to visualize) } //Here we're printing "ER" Followed by the error message numbers. /*Because the memory addresses in the IIC library count from 0, you must subtract by 1 to go from the ordinal counting system to go to zero-based. To write to the bottom line of the lcd, the ordinal number of last line (lcdH) must be reduced by one (lcdH - 1), (in a 16x2 the second line is line 1) otherwise the Arduino writes to off-screen regions of the lcd. (In the case of a 4-Row LCD, memory line address "4" is actually non-existant line 5 ) Because there might be data in the earlier parts of the bottom line of the LCD, the cursor is set to print to the far right on the bottom line. To do this, the cursor is set to the right the pre-calculated number of characters (NumERR, calculated in erUpdate) needed to print all of the error messages plus the two characters needed to print the letters "ER" */ } } void erUpdate() { if (er1 =- true) { erStr += "1"; //add char (not int) "#" to string. # is the number in parenthesis. //This is true for all of the code in erUpdate below too. } if (er2 =- true) { erStr += "2"; } if (er3 =- true) { erStr += "3"; } if (er4 =- true) { erStr += "4" } if (er5 =- true) { erStr += "5"; } if (er6 =- true) { erStr += "6"; } if (er7 =- true) { erStr += "7" } if (er8 =- true) { erStr += "8" } if (er9 =- true) { erStr += "9" } } void tempUpdate(){ } switch(TN){ //Switch case based on how many thermometers are connected case 0: break; case 1: TM0 = ((analogRead(TR0) * (5000/1024))-500)/10; break; case 2: TM0 = ((analogRead(TR0) * (5000/1024))-500)/10; TM1 = ((analogRead(TR1) * (5000/1024))-500)/10; break; case 3: TM0 = ((analogRead(TR0) * (5000/1024))-500)/10; TM1 = ((analogRead(TR1) * (5000/1024))-500)/10; TM2 = ((analogRead(TR2) * (5000/1024))-500)/10; break; case >=4: er2 = true; break; } void lcdTempUpdate(){ } switch(TN){ //Switch case based on how many thermometers are connected case 0: break; case 1: TM0 = tCon(TM0); lcd.setCursor(0,0); lcd.print("T0"); lcd.print(TM0); lcd.setCursor(0,15); lcd.print(unit); break; case 2: TM0 = tCon(TM0); TM1 = tCon(TM1); lcd.setCursor(0,0); lcd.print("T0"); lcd.print(TM0); lcd.setCursor(0,6); lcd.print("T1"); lcd.print(TM1); lcd.setCursor(0,15); lcd.print(unit); break; case 3: TM0 = tCon(TM0); TM1 = tCon(TM1); TM2 = tCon(TM2); lcd.setCursor(0,0); lcd.print("A"); lcd.print(TM0); lcd.setCursor(0,5); lcd.print("B"); lcd.print(TM1); lcd.setCursor(0,10); lcd.print("C"); lcd.print(TM0); lcd.setCursor(0,15); lcd.print(unit); break; case >=4: er2 = true; break; } tCon(int Q){ if (tUnit == True) { Q = (9*Q)+32 } return Q; } SerTemp(){ switch(TN){ //Switch case based on how many thermometers are connected case 0: break; case 1: Serial.println(""); Serial.println("Thermometer 0"); Serial.println(TM0); Serial.println(""); break; case 2: Serial.println(""); Serial.println("Thermometer 0"); Serial.println(TM0); Serial.println(""); Serial.println("Thermometer 1"); Serial.println(TM1); Serial.println(""); break; case 3: Serial.println(""); Serial.println("Thermometer 0"); Serial.println(TM0); Serial.println(""); Serial.println("Thermometer 1"); Serial.println(TM1); Serial.println(""); Serial.println("Thermometer 2"); Serial.println(TM2); Serial.println(""); break; case >=4: er2 = true; break; }


EDIT:
It looks really bad here so I'm going to save it into a CPP file and put it up for download so it can be viewed on
the Tutorials Point Online IDE or on your favorite CPP editor. (I'm using a cpp editor rather than the Arduino IDE because my sister is hogging the Mac and I'm stuck on a Chromebook without access to JRE. They have the same format so it doesn't change much other that the ability to compile.)

EDIT:
I'm hosting it on my blog so I can manage versions of the code.
http://theexperimenterlife.blogspot.com/
Look on the top right where there is a widget that says "Downloads"
It's the top right one that says "Temperature Datalogger (V0-0) 1-9-15"
For the record, all of my non-libraries will be managed by version followed by date,
so this is Version 0.0 and Date 1/19/15.



[Edited on 10-1-2015 by andymadman]

ahill - 11-1-2015 at 17:03

Wow - good work !

You've shamed me - I will have to get a usable temperature probe(s) happening myself.

Have you used your program in anger yet ? If so - what are you using for your temperature probe ?

I've ordered this glass adapter from deschem - but still have to decide what to use for the actual probe.

Earlier you mentioned a "10k SS thermometer" - is this the sort of thing you are talking about ? - the price is right - do you have any experience with using something like this with an arduino ?

[Off Topic] Your quote code looks OK here - but you know you _can_ kind of use the arduino IDE / eclipse / whatever from your chromebook by tunneling X sessions from the mac :- this guy talks about how he did it.

andymadman - 12-1-2015 at 15:02

Quote: Originally posted by ahill  
Wow - good work !

You've shamed me - I will have to get a usable temperature probe(s) happening myself.

Have you used your program in anger yet ? If so - what are you using for your temperature probe ?

I've ordered this glass adapter from deschem - but still have to decide what to use for the actual probe.

Earlier you mentioned a "10k SS thermometer" - is this the sort of thing you are talking about ? - the price is right - do you have any experience with using something like this with an arduino ?

[Off Topic] Your quote code looks OK here - but you know you _can_ kind of use the arduino IDE / eclipse / whatever from your chromebook by tunneling X sessions from the mac :- this guy talks about how he did it.


Thank you! :)

That is the kind of thermometer I was originally thinking of, but I realized that something like this would probably work better as they sell them for much, much cheaper on amazon, comparable ones are usually a dollar for a 25 pack. If you think it's a good idea, I could put something in the code to allow either kind of temperature sensor by having a Boolean in the human-controlled variables. I'm just worried that I'm going to exceed the maximum program size if I put too much in. I've done that a few times now and it's always a bummer having to spend hours shaving off bytes to get everything to fit onto the Arduino.

In regards to the temperature probe itself, I have used them before and they work quite well. They're usually accurate to around +-5 degrees at high-ish temperatures and +-1 degree around room temp. Usually I have them heat-pasted to a motor driver on a robot to prevent them from overheating.

Sadly I can't tunnel to use the Arduino IDE as my sister is usually actively using the Mac on her profile and because of the way it's set up, I couldn't access my sketches as she doesn't have read/write privileges to my directory.

ahill - 12-1-2015 at 16:55

Ah - the TMP36 - I think maybe the first sensor I ever used with an arduino ! They are good - but kind of limited - best around room temperature - not so good past 100C. I also found them kind of big once you start thinking about putting them in a glass or plastic tube. (I'd really like something I could use as a drop-in replacement for a traditional glass thermometer, and also something that can take several hundred degrees)

I briefly messed with trying to monitor the temperature of an electrolytic cell - at one point I was planning to wire a TMP36 up, then dip it in epoxy to protect it. (The environment in the cell was crazy corrosive - I did try stainless steel tubing, shrinky tubes, and hot glue - all with predictably poor results). If I were to revisit that project, I would prolly try heat sealing one of those 4k probes in a flint glass tube.

For now I am waiting on my 24/29 glass thermometer adapter and 4k probes from ebay.

btw - you _can_ run graphical X-windows apps tunneled over ssh from the mac using your account, while your sister is locally logged in with her account - its not windows - your mac has a proper multi-user OS under the hood. (BSD Unix no less). The only real conflict would be if she were to shutdown, or take it off the local network while you were using it.

The Volatile Chemist - 12-1-2015 at 17:11

If you ask me, PICs and Picaxe are the best, but that's just because I prefer Z80s, and those are the best modern derivatives, though they're technically slightly different.

Metacelsus - 12-1-2015 at 17:24

I use PICs a lot; they're less powerful than Arduinos, but also a lot cheaper and simpler.

andymadman - 12-1-2015 at 20:45

Quote: Originally posted by ahill  
Ah - the TMP36 - I think maybe the first sensor I ever used with an arduino ! They are good - but kind of limited - best around room temperature - not so good past 100C. I also found them kind of big once you start thinking about putting them in a glass or plastic tube. (I'd really like something I could use as a drop-in replacement for a traditional glass thermometer, and also something that can take several hundred degrees)

I briefly messed with trying to monitor the temperature of an electrolytic cell - at one point I was planning to wire a TMP36 up, then dip it in epoxy to protect it. (The environment in the cell was crazy corrosive - I did try stainless steel tubing, shrinky tubes, and hot glue - all with predictably poor results). If I were to revisit that project, I would prolly try heat sealing one of those 4k probes in a flint glass tube.

For now I am waiting on my 24/29 glass thermometer adapter and 4k probes from ebay.

btw - you _can_ run graphical X-windows apps tunneled over ssh from the mac using your account, while your sister is locally logged in with her account - its not windows - your mac has a proper multi-user OS under the hood. (BSD Unix no less). The only real conflict would be if she were to shutdown, or take it off the local network while you were using it.


Okay. I've used a couple of TMP36-alikes with a Spark Core in the past to monitor and control the temperature of electrolysis of magnesium sulfate to make copper sulfate, and then have it upload and log the results on a secondly basis to a server. It worked pretty well, but I've never had to use them at temperatures over 100C so I am unaware of how they work at higher temperatures. I usually just completely covered it in ceramic inside the tube of a cheap plastic pen. I did try sealing one in a boro-glass tube, but the high temperature killed it.

In regards to the Mac, my sister is usually editing videos or similar tasks and running the two processors at 90%+ each, so there's very little processing power left for other programs to run. I've only used Ubuntu in the past and had problems windowing X11 over a proxy. I'll look into it, but my guess is with my lack of admin/fakeroot privileges I'm not going to be able to run the root-privilege processes required.

Thanks though for the information, it is greatly appreciated!

The Volatile Chemist - 13-1-2015 at 06:54

Quote: Originally posted by Cheddite Cheese  
I use PICs a lot; they're less powerful than Arduinos, but also a lot cheaper and simpler.

I wouldn't say that, unless you're revering to the picaxe, not PICs (by Microchip).

pneumatician - 15-1-2015 at 17:02

can this platform generate TRUE random numbers via quantum noise?

ahill - 15-1-2015 at 20:41

No.

Well - it would if you had a quantum noise sensor.

Does atomic decay count ?

'cause look what I found on the internet. (how cool is the internet ?)

http://www.instructables.com/id/Arduino-True-Random-Number-G...

..so I dont know if the random numbers would actually be random - but they'd certainly be cool - so I'd sign my certificates with them any day !

pneumatician - 30-1-2015 at 16:49

well in this page many ideas but i think not enough good.

really is easy to get TRN from quantum noise. I contacted with elektor usa but no reply.

this use exclusive code, in C? ASM? basic?
http://www.trng98.se/shop/product_info.php?products_id=33

this use a fucking USB Interface
http://www.psyleron.com/reg1_lite.aspx

this with obscene prices :)
http://www.idquantique.com/random-number-generators/products...