Showing posts with label pHduino. Show all posts
Showing posts with label pHduino. Show all posts

Friday, July 13, 2012

Controlling the pHduino with a Python-Jabberbot script

Introduction

This is a simple suggestion to control the pHduino over Internet using the  Python-Jabberbot framework. It could be interesting, for example, if you want to monitor the pH of an aquarium from your work or using your smartphone from anywhere.

Of course you can change the python jabberbot script to control other devices over USB-Serial and an IM connection. It works well for slow streaming of messages. XMPP protocol is open, widely accepted, and works fine with python for multi platform solutions. There are many clients that use the XMPP protocol.

You will need:
  • a pHduino working.
  • a computer (Linux or Windows) with an internet connection and a USB port with the virtual comm port (VCP) working.
  • two XMPP instant messages accounts (jabber.org, Google Talk...) and changing messages between them.
  • the Python interpreter with the modules python-setuptools, python-serial, python-xmpp, and python-jabberbot.
  • The python jabberbot script to control the pHduino.

I described the process for Linux and Windows. I did not test it for Mac but the users could test the Windows procedure.

Software dependence

Python 2.7.3

Python Setuptools 0.6c11

Python Serial 2.6

Python XMPP 0.5.0-rc1

Python Jabberbot 0.15

Check for packages updates and pay attention with the Python version.

pHduino

I am assuming the pHduino working properly by USB-Serial port.

First of all, it is important change the pHduino parameter interval_ms from 1000 to 10000 or more. The reason is to not flood the IM with too many messages to not difficult the human reading and reduce the traffic of messages on the Internet. To do this you need a serial terminal to set the parameter. My suggestions: cutecom for Linux (http://cutecom.sourceforge.net/), terminalbpp for Windows (https://sites.google.com/site/terminalbpp/), and screens for Mac.

Select baudrate 115200 for the firmware version v041 and No Line End to send strings. Open the connection and type

cmd interval_ms 10000

You will listen a beep. Now, you have a message by serial every 10s.

XMPP accounts

You need two IM accounts that uses the XMPP protocol. One account for pHduino and another one for you access the pHduino from anywhere. The accounts could be both from Google Talk, or both from Jabber.org, or one from the Google Talk and another one from the Jabber.org. Anyway, what is important is the XMPP protocol. Don't forget to add the contacts in the lists of each other.

Software installing for Linux

For Linux users the software install is simple because you can find all programs in the repositories. The package name could be different if you are using a different Linux distribution. I am using the Ubuntu 12.04.

Probably, the Python interpreter is already installed.

Now, you need the python serial module. Open a terminal and type

sudo apt-get install python-serial

Install the the Jabberbot. The xmpppy (python-xmpp) dependence will be installed.

sudo apt-get install python-jabberbot

In case your Linux distribution does not have the modules jabberbot and xmpppy in the repository, you must download, build, and install them. To do this, install the python-setuptools.

sudo apt-get install python-setuptools

Software installing for Windows

I tested the the python jabberbot script in an Windows 7 64-bits and it worked.

Python

Download and install the Python 2.7.3 Windows Installed (Windows binary -- does not include source) from

http://www.python.org/download/

There is a detail to work: be sure the python directory distribution is in the PATH environment variable. Go to Start -> Control Painel -> System -> Advanced System Settings -> Environment Variables. Look for the PATH variable at System Variables and edit it adding at the end of the line (take care to not overwrite your settings). The procedure is similar for Windows XP or Vista. Append the following string.

C:\Python27;

To test, open a command prompt (Start -> Programs -> Acessories -> Command prompt) and type python and press enter. You should have the python interpreter. Type quit() to quit.

pyserial

To open a serial connection with the pHduino install the python-serial module. I installed the old version pyserial-2.5.win32.exe from

http://sourceforge.net/projects/pyserial/files/pyserial/2.5/

Setup-tools

Next, install the python-setuptools to build and install the xmpp and jabberbot modules. Download and execute the file setuptools-0.6c11.win32-py2.7.exe from

http://pypi.python.org/pypi/setuptools/

No problem if the file is win32 binary and the Windows 7 is 64-bit.

xmpppy

You must build and install the module by the sources because there is no exe or msi file. Download the xmpppy-0.5.0rc1.tar.gz from

http://xmpppy.sourceforge.net/

I suggest you install the 7-zip because it can unpack .tar.gz (or .tgz) files. Download the 64-bit version if your Windows is 64-bit.

http://www.7-zip.org/

Right click on xmpppy-0.5.0rc1.tar.gz and extract here option. This operation generates a .tar file. Again, right click and extract here. Copy the xmpppy-0.5.0rc1 directory to C: and rename it to xmpppy just to make the job easy.

Open a command prompt and type

cd C:\xmpppy
python setup.py build
python setup.py install

You will see a list of directories during the install process. Do not forget to remove this directory from the C:\ when all is finished.

Jabberbot

Download the jabberbot-0.15.tar.gz from

http://thp.io/2007/python-jabberbot/

Again, extract it in the same way of xmppy and rename it to jabberbot. Move it to C:/ and type

cd C:\jabberbot
python setup.py build
python setup.py install

Again, you will see the list of directories during the install process. Remove the jabberbot directory when the job is done.

Python Jabberbot script

This python script is simple because the jabberbot framework simplify the configurations. There is a difference between the python jabberbot framework (the python module) and the python jabberbot script (the code to control the pHduino).



You can download the phduino_jabberbot_v01.py from the pHduino project.

In the script above, you need edit the username, password, and recipient variables. username and password is the account for the computer with the pHduino to connect by USB. recipient is your account that receive the messages from the pHduino. Edit the serial_port and baud_rate. Save it and run it by clicking or by typing the command on the command prompt or terminal

python phduino_jabberbot_v01.py

You will see the initial messages from the script. Let's test from your IM account.

Open your xmpp account in the same computer or in another computer using your favorite IM client. When you finish the logging, you will receive messages like

18.6 375 27 6.53 1 0
18.6 375 25 6.56 1 0
18.6 375 25 6.56 1 0
18.6 375 25 6.56 1 0
18.6 375 27 6.53 1 0

Description of the columns: (1) temperature (celcius), (2) ADC value, (3) electrochemical potential (mV), (4) pH, (5) alarm enabled flag, and (6) alarm flag (0 for pH in the limits and 1 for pH out of the limits).

pHduino operation

For the help, type

cmd help

and you will see

cmd help
cmd phduino start|stop
cmd interval_ms INT
cmd set_temp_sensor on|off
cmd set_temp FLOAT
cmd set_ph_alarm PH_INF PH_SUP
cmd ph_alarm on|off
cmd reset

If you want stop the strings, send the command

cmd phduino stop

To return to receive them

cmd phduino start

To set the pH range for the alarm type

cmd set_ph_alarm 6.0 8.0

This example set the alarm range from pH 6.0 to 8.0.

To turn the alarm on, type

cmd ph_alarm on

You will see the alarm flag with value 1 and the pHduino will start beeping indicating that the pH is out of range. Remember that without a pH sensor connected you will see the pH saturated (pH 15.03 or similar value) and out of range like

18.5 834 -437 15.03 0 0

To turn the alarm off, type

cmd ph_alarm off

If you have a thermostatized system (system with the temperature controlled), you don't need the temperature sensor. Just set the temperature and disable the temperature sensor. For example

cmd set_temp 20.0
cmd set_temp_sensor off

To reset all parameters to default values, type

cmd reset

And remember: pH notation is lowercase "p" and  uppercase "H".
Good hacks.

Saturday, January 1, 2011

pHduino Datalogger shield released

Feliz Ano Novo!

De pHduino Datalogger

At the begin of the 2010, I developed a datalogger shield for the pHduino. Again, I decided to make something simple to mount, modify, and use. I put the project in stand by because I need improve the code. Yesterday, I resolved make the modifications and I released it today. You can download the hardware and firmware files from the page of the project.

Tuesday, September 7, 2010

pHduino gerber files

Olá.

I have received some e-mails about people interested to buy a pHduino shield. But, I can't sell it, yet. The reason is I used the Eagle Free version (I can't make money with this version). Another reason is the business tax is very hard here in Brazil. Therefore, it is better you make your our PCB shield. I will resolve this problem in the next version.

Today, it is easy to make a PCB at home using laser print toner to make the mask for the corrosion. There are a lot of tutorials on the internet describing how to make good PCB. But, sometimes, you don't have time to make a PCB or don't have ability for it. In this case, my suggestion is generate gerber files and send to a PCB manufacturer. There are a lot of services on the internet. You only need select one with a good rate between money and time.

I generated the pHduino gerber files and made them available for anyone that wants to order a PCB from a PCB manufacturer.

Decline

Use these files for your own risk. I am not responsible if your lost money or they do not work. There are many variables involved and I can not be responsible for any mistake.

If someone detect an error, please send me a message. I will really appreciate for your help or suggestions.

Thank you and good luck.

Wednesday, April 21, 2010

pHduino Firmware v041 released

Hi everybody.

It is a newest release of the pHduino firmware with some little modifications. The most import addition is a magic number to simplify the pHduino operation.

Sunday, September 20, 2009

pHduino Firmware v04 released

Again, one more pHduino firmware release. Two main features: pH alarm, to warn when the pH is out of the normal range, and save parameters in the Arduino EEPROM memory, to recover the last configuration after a reset or a power off.

Changelog v04_20090920
  • Changed file name from phduino.h to pHduino.h.
  • Added codename version.
  • Added function to set the pH range for the pH alarm. 
  • Added pH alarm signals: LED, beeps, message by serial port and LCD.
  • Added feature to save parameters in the EEPROM memory of the Arduino board.
  • Added function to reset parameters in the EEPROM.
This is the newest list of commands.

cmd help
cmd phduino start|stop
cmd interval_ms INT
cmd set_temp_sensor on|off
cmd set_temp FLOAT
cmd set_ph_alarm TEMP_INF TEMP_SUP
cmd ph_alarm on/off
cmd reset

The code still fits in an Atmega168.

If you are using the pHduino in some project, send me the link to make a post about your project. I will really appreciate post a list of links about related projects.

Blog
http://phduino.blogspot.com

Project
http://code.google.com/p/phduino

Sunday, September 13, 2009

pHduino Firmware v03 released

This is the newest version of the pHduino firmware. Now you can configure it using a serial port communication.
  • Fixed comment about time of one 60Hz cycle in phduino.h file.
  • Added time for 50Hz power line.
  • Added command line feature to configure the pHduino.
  • Added option to work without temperature sensor by setting a temperature value by command line.
  • Added option to configure the time interval between acquisitions.
  • Added option to start/stop data sending by serial.
  • Added a help function.
I decided to use a command line function described in the Arduino forum, because I can write command close to the spoked language. This the output help function.

cmd help
cmd phduino start|stop
cmd interval_ms INT
cmd set_temp_sensor on|off
cmd set_temp FLOAT

For example, to make pHduino stop to send data, send the command "cmd phduino stop" (without quotes, of course). Interval time option configures the time interval between acquisitions in mili seconds (use values greater than 500). INT is an integer value and FLOAT is a decimal point value.

Now you can use it without the LM35 temperature sensor. For this, pass the command "cmd set_temp_sensor off" and set a temperature value. For example, "cmd set_temp 18.4" to set 18.4 celcius degrees up.

There is no problem using the serial terminal of the Arduino software. However, using a serial terminal program you need set to send strings without line end characters [carry return (CR) and linefeed (LN)]. I made tests using the cutecom (very common in Linux distributions) and it worked fine. For Windows users I suggest to use the Realterm. Mac OSX users can use the screen program.

pHduino Project
http://code.google.com/p/phduino

Sunday, August 30, 2009

pHduino 0.2 released

A new pHduino hardware version was released. The problem about sensor voltage offset compensantion was resolved. See the changelog for the changes.



Changelog - Hardware version 0.2
  • Fixed the problem of the offset signal amplification before the compensation.
  • Increase the value of the resistors to reduce the electric current consume (Dr. do Lago).
  • Changed the charge pump inverter capacitors from 1000uFx6.3V to 100uFx25V.
  • Removed zener diode and trimpot used to adjusts the voltage reference by a resistor of fixed value.
  • Added a ADC channel to reads the reference voltage.
History

Friday, August 21, before to get sleep, I had an idea to resolve the offset signal compensation problem with gain. On Saturday and on Sunday, I changed the PCB layout and did a clean-up on the firmware code.

On Monday, 24, I changed the electronic circuit of the first version to the new circuit. Dr. do Lago helped me selecting the right value of the resistors to reduce the current consume.

On Wednesday, 26, my friend Mr. Vidal, realized a comparative test between the pHduino and a pHmeter from a commercial brand using a titration of HCl with NaOH in a didactic laboratory. He said me the pHduino worked fine. The results I will show soon.

On Friday, 28, I made a PCB with the new layout, on Saturday, 29, I bought more electronic components and I mounted the circuit at my home toolshop.

Today, Monday, 31, I took some new shots of the circuit mounted.

The solution

The basic idea to resolved the main problem is apply an adjustable electric potential, using a trimpot, at the place of the voltage divider ground of the non-inverter amplifier (Stage1). Dr. do Lago deduced for me the equation for the Stage1.



I know that this point does not have a low impedance. I should put a follower voltage. However, the current that flows by the R1 and R2 is about 100 times lesser than the current that flow by the voltage divider (defined by R3, R4, and R5) that applies the voltage offset at R1. This circuit is suitable for this application.

pHduino Project
http://code.google.com/p/phduino

Tuesday, August 11, 2009

Circuit released

I am really sorry about the delay. But, just before to publish the electronic schemes and the PCB layout I decided to make some changes. Now I published the first public version of the pHduino hardware scheme and PCB. I have a code example but I need clean it up.

One change was remove a gain adjust trimpot to a fixed value resistor. This change makes me know exactly the voltage of the glass electrode. In the beginning of the project, the trimpot did make me sense for a better use of ADC range. But, tests show me that the operation was a little bit complicated.

About the offset adjust trimpot, I decided to keep it, because each electrode will give an electrical potential different from zero at pH 7.00.

I changed the position of some components for a better layout and put the operational amplifier input near the connector terminal.

I am still feeding the project with documentation. So, I am sorry about the lack of information. I will really appreciate suggestion.