Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
francis.thibault24@gmail.com  
#1 Posted : Monday, April 13, 2015 6:38:33 PM(UTC)
francis.thibault24@gmail.com

Rank: Newbie

Groups: BetaUser, Registered
Joined: 4/2/2015(UTC)
Posts: 8
Canada
Location: Montreal

I tried the 4 pin ultrasonic sensor within the arduino IDE and it is working well.

Within the Embrio, there is no change at all for the Activation output, it seems that there is no input read.

Any hint?

Thanks.

This is the code used, the one I found into your Custom Node Arduino Library->Inputs.

<Nodes>
<Node>
<UniqueID>726902f2-6bc5-4a82-85b3-794a8ff1843f</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName>4 Pin Ultrasonic Sensor</UserDefinedName>
<Description>A node that lets you write any Arduino code to interact with the Arduino hardware. Can be both an input and output.</Description>
<NodeColor>201,204,227,255</NodeColor>
<X>0</X>
<Y>0</Y>
<Width>512</Width>
<IncludeCode></IncludeCode>
<DeclerationCode>int echoPin = 7;
int trigPin = 8;
int maxPulse = 100; // Maximum micros to wait for a pulse
long duration;
</DeclerationCode>
<SetupCode>pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
</SetupCode>
<ImageName>185FD26C2851.png</ImageName>
<InfoURL>http://embrio.io/custom-arduino-nodes/inputs/distance-sensors/4-pin-ultrasonic-sensor</InfoURL>
<CodeDefinitions>
<CodeDefinition>
<UpdateCondition>EveryUpdate</UpdateCondition>
<Code>digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, maxPulse);

Output_Activation = transform(duration, 0, maxPulse, 0.0, 1.0);
</Code>
<UniqueID>412bc09a-957a-4afb-bca6-32497120f10a</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs>
<Input>
<UniqueID>dd7cb568-36f9-4c51-85d9-b812cca9e8f4</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Trigger</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Trigger</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.TriggerNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
</Input>
</Inputs>
<Outputs>
<Output>
<UniqueID>a76fff89-5e54-4a78-a65f-c2c0eb30756b</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>True</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
</Outputs>
</Node>
</Nodes>

Edited by user Monday, April 13, 2015 6:39:10 PM(UTC)  | Reason: Not specified

EmbrioAdmin  
#2 Posted : Monday, April 13, 2015 7:33:15 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 81 time(s) in 76 post(s)
It looks right to me.

I would try to figure out what the duration value is to see where things are going wrong. Add a text output and add "Output_Text = ToString(duration);" to the end of the update command. Is it showing you a value between 0 and 100? If it's 0, are you sure that the same code as in the update command returns a duration value when compiled through the Arduino IDE?
EmbrioAdmin  
#3 Posted : Monday, April 13, 2015 7:35:54 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 81 time(s) in 76 post(s)
Keep in mind the 3rd parameter of the pulseIn function is a timeout. If you're not getting a reading within 100 microseconds it'll return a 0: http://arduino.cc/en/Reference/pulseIn

Could you be using a different maxPulse value in Embrio than in the Arduino IDE?
Afulki  
#4 Posted : Tuesday, April 14, 2015 2:30:17 AM(UTC)
Afulki

Rank: Member

Groups: Registered
Joined: 4/8/2015(UTC)
Posts: 10

Thanks: 2 times
I had ro use a time of 1000ms with the paralaxping (3-pin) to get any readings, this may need similar
francis.thibault24@gmail.com  
#5 Posted : Tuesday, April 14, 2015 2:24:30 PM(UTC)
francis.thibault24@gmail.com

Rank: Newbie

Groups: BetaUser, Registered
Joined: 4/2/2015(UTC)
Posts: 8
Canada
Location: Montreal

That's right. If we want to detect a longer distance, we have to increase the maxPulse.

In the Adruino, the third parameter of the function pulseIn is not present.

Thanks all.
EmbrioAdmin  
#6 Posted : Tuesday, April 14, 2015 2:40:37 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 81 time(s) in 76 post(s)
The third parameter isn't needed, you can leave it out and use the default timeout of 1 second. The problem is if there's a problem with the sensor and pulseIn times out after waiting for a full second, the compiled program will hang for that second, basically breaking the program. So you should use the timeout and set it to as low as you can for your application.
SomeAssembly  
#7 Posted : Wednesday, June 10, 2015 6:30:42 AM(UTC)
SomeAssembly

Rank: Advanced Member

Groups: BetaUser, Registered
Joined: 3/31/2015(UTC)
Posts: 47

I use 5555 as my time out setting, this works out to about 1 meter.

I also have added: if(duration == 0) duration = maxPulse;
before the transform statement, this makes sure that greater distances always give a 1 instead of 0. So that 1 is = 1 meter of more and 0 = very close.

Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error