arduino and propeller communication as a button
johnproko
Posts: 121
I can find a way to measure temperature with the propeller and thus moved to the second best solution to provide the the temperature from the analog reading of the arduino.
It goes like this: arduino measures the analog value and breaks it down into 4 digits (DA.BC). Depending on the temperature these value will trigger a high/low state in the arduinos digital pins (35.22C will be 3pulses of D, 5 of A, 2 of B and 2 of C). Then the propeller will run an if statement until the Portal closes (4 pins for the data and one to open/ close the if statements). The problem is that propeller is constantly showing the message that is suppose to be shown only if the portal is open.
For the test im using a simple high/low from the arduino with 1s open, 5s closed.
For the propeller:
int SO;
int main()
{
SO = input(16);
while(1)
{
if (SO == 1)
{
print("Hello from ard");
pause(500);
}
}
I have attached a photo showing the wiring between them. Any ideas why it is failing to do that? I read in the forum that one can use one wire to transfer data between them. Is there anyone that has a photo of the wiring and a sample code?
It goes like this: arduino measures the analog value and breaks it down into 4 digits (DA.BC). Depending on the temperature these value will trigger a high/low state in the arduinos digital pins (35.22C will be 3pulses of D, 5 of A, 2 of B and 2 of C). Then the propeller will run an if statement until the Portal closes (4 pins for the data and one to open/ close the if statements). The problem is that propeller is constantly showing the message that is suppose to be shown only if the portal is open.
For the test im using a simple high/low from the arduino with 1s open, 5s closed.
For the propeller:
int SO;
int main()
{
SO = input(16);
while(1)
{
if (SO == 1)
{
print("Hello from ard");
pause(500);
}
}
I have attached a photo showing the wiring between them. Any ideas why it is failing to do that? I read in the forum that one can use one wire to transfer data between them. Is there anyone that has a photo of the wiring and a sample code?
Comments
There are a few common ADCs with objects already written for the Propeller. The OBEX has lots, Simple comes with functions for whatever chip the Activity Board uses (and maybe others?) and PropWare comes with a class that works with any MCP3xxx series device.
Once you have the temperature stored as a voltage, it's a simple math equation to convert to degrees F/C. The datasheet for your thermometer will tell you what the math is, and we here on the forums would be happy to help you decipher it if needed (we'll of course need the part number or datasheet though).
Nevertheless I would like to know about arduino - propeller communication.
We are not all computer programmers or electricians in order to understand, and I lack the time to read a 300page book when My daily job requires reading 500 pages of accounting laws that tomorrow will have changed and I need to start over again.
No offence :-)
Then why don't you use Spin? It has less problems than C (when used on the Prop, at least), and is better supported and there are more drivers written for it.
I promise, doing it in C won't add any more problems . (Of course... that's pretty subjective). You don't need to understand the nitty-gritty details of how ADCs work. Simply understand that a voltage with a range goes in (the thermistor signal) and out comes a stream of bits, representing the temperature as a binary number. Interpreting that stream of bits is the hard part.
Buuuut... that's what libraries are for! You don't have to do the hard part of interpreting the stream of bits because you can download code that does it for you. If you don't own any ADCs yet, then I recommend you purchase an MCP3208. It's cheap, it's simple, it's extremely common, and it has lots of channels to measure lots of different different things. Here you can purchase one for a whopping $3.50.
Once you have it in your hand, you can use PropWare (instructions for using with SimpleIDE here) to communicate with it (API docs here).
Your code might look something like this:
For this, you might be better served by using standard serial communication instead of creating your own custom protocol. UART is a good serial protocol for chip-to-chip communication. UART is the same protocol that the Propeller and the Arduino use for communicating with your computer. The only difference is that you are going to want to use different pins when communicating with a chip than when communicating with your computer.
The unfortunate thing is that you have been tricked. To make your life easier, certain UART functions were invoked without you ever knowing. Specifically, those are the initialization functions, including the ones that set the pins. This is because most users want to use the same pins at the same baud rate and all the same settings, all the time. So the library author does this behind the scenes so that your life is easy.
For instance, how does this code work???
And Arduino has a similar concept with its Serial library
Where did print/Serial come from? How does it know where to print? How does it know how fast to print? What is this MAGIC?!?!?
To communicate between two different chips, you'll need to be able to answer these questions. You need to:
1) Instantiate a (new) serial object. This is the object that is capable of serial communication on custom pins.
2) Configure the pins on the new serial object.
3) Configure the baud rate on the new serial object.
4) Transfer from the Arduino to the Propeller.
5) (Optional) Echo a reply from the Propeller to the Arduino.
I'll start with the Arduino. I found here the documentation for SoftwareSerial's constructor. It shows that we should be able to write some code like...
This code should send "Hello\n" out of pin 3 on the Arduino once every second. So now, let's set up code on the Propeller to receive it. We're going to use PropWare::FullDuplexUART for this.
Okay, this is all I have time for at the moment, but it should (might) work.
I've written a SIMPLEIDE C library and demo programs. They are attached to:
forums.parallax.com/discussion/comment/1315065/#Comment_1315065
I think the instructions for using the library are pretty clear, but ask if necessary.
There is a demo using the 3208 8 channel 12 adc. It should also work with the 3204, but you probably have to change the pins defines.
Your original version read the input once, then continuously checked the resulting value and printed the output. Nothing ever changed that value again, so the output was continually displayed. By moving the "SO = input(16)" statement inside the while loop, you now update the SO variable every loop iteration, immediately before deciding whether to display the message.
Still the code doesnt change the result. A high pulse from the arduino is not triggering the if statement.