Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
FCazana  
#1 Posted : Tuesday, February 14, 2017 6:21:24 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Hi,

I connected a senson HC-SR04 to my arduino nano in the pins Echo 7 and Trig 8. I created a node "4 pin ultrasonic sensor", I connect with my arduino nano board and it does not give errors.

But I have no output value from the node. I use V 1.3.6.0. Any idea what's going on?

Thank you
EmbrioAdmin  
#2 Posted : Tuesday, February 14, 2017 7:17:46 AM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Not really enough into to go by. Could you open up a serial monitor from the Arduino ide and listen at 57600 and fell me what you see?
FCazana  
#3 Posted : Wednesday, February 15, 2017 2:29:59 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Hi,

I have tried a similar code in arduino ide and it returns me the correct measurements. I'm going to try what he says, but I have a free embryo license and I do not know if this is possible.

Thanks
FCazana  
#4 Posted : Wednesday, February 15, 2017 4:00:06 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Hi,
I do not know if I did it right, the arduino printed a COM8 buzy error. But then I have the "embrio" code inside arduino IDE and I have uploaded it to the board. On the console at 57600 and I only get this UPD: 5: 0: 00.

Thanks
EmbrioAdmin  
#5 Posted : Wednesday, February 15, 2017 4:20:19 AM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Looks like the connection program uploaded correctly. It is sending back a value of 0 to embrio to display. Make sure the code in the embrio node has the correct pin numbers. Can you confirm that it does?
FCazana  
#6 Posted : Wednesday, February 15, 2017 6:42:49 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Hi,

Embrio by default assigns Echopin = 7 and Trigpin = 8 and I have connected the HC-SR04 Echo output to D7 and Trig to D8. With this configuration, just using a node "4 pin ultrasonic sensor" the value of "Activation" should vary, right?

Thanks
EmbrioAdmin  
#7 Posted : Wednesday, February 15, 2017 6:52:12 AM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Yeah I think it should, assuming all the hardware is working.

Most of the code in that Arduino node is very straighforward Arduino code, the only Embrio specific piece is the last line that converts the "duration" value to a value between 0.0 and 1.0. To debug you can copy the code from the node into an Arduino program in the appropriate spots, and then Serial.print the duration value. If you see it changing then there is maybe something wrong with the Embrio compiled program which I can investigate. If the duration is not changing there's probably a setup problem, or that Arduino code is wrong.
FCazana  
#8 Posted : Wednesday, February 15, 2017 7:33:57 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

I have tried the code in Arduino IDE and it always returns me 0, I thing is the same in embrio;

This is the arduino code:

int echoPin = 7;
int trigPin = 8;
int maxPulse = 100;
long duration;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

Serial.begin(9600);
}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, maxPulse);
Serial.println(duration);
delay(1000);
}
EmbrioAdmin  
#9 Posted : Wednesday, February 15, 2017 7:36:01 AM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
You said earlier that you were able to get good measurements in the arduino ide. Could you post that code? Or try pasting it into a custom arduino node, copying the last step to convert the value to an activation output.
FCazana  
#10 Posted : Wednesday, February 15, 2017 7:57:29 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Try using a custom node with the arduino code but it gave me error: Compile error Node dont have IO called "output_Activation". Even if I had Output_Activation in the code. I'm going to look for a code that will work with the measurements and upload it.
EmbrioAdmin  
#11 Posted : Wednesday, February 15, 2017 8:02:37 AM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Make sure the node actually has an output activation. Add it by clicking on the little icon on the node on top, mouse over the add output icons to make sure you add an activation.
FCazana  
#12 Posted : Thursday, February 16, 2017 1:40:44 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Hi,

Now it works, I've changed some things from the "4 pin ultrasonic sensor" node to return the measured distance. Thank you.

<EmbrioCopy>
<Version>1.3.6.0</Version>
<Nodes>
<Node>
<UniqueID>63f96cb5-c937-4b08-a8af-031eb110a645</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.DynamicNode</AssemblyType>
<NodeType>Value Lag</NodeType>
<UserDefinedName></UserDefinedName>
<Description></Description>
<NodeColor>201,227,222,255</NodeColor>
<X>552.666666666667</X>
<Y>780</Y>
<Width>260</Width>
<DefinitionID>0a04d06b-b740-4ef4-a297-e0fe23b0d11d</DefinitionID>
<Inputs>
<Input>
<UniqueID>859cd351-837f-43e1-adb3-3caf86cf5c28</UniqueID>
<DefinitionID>94b26858-501f-498c-90ba-40017e2349ab</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>False</IsUserAdded>
<ConnectedOutputs>
<Output>84297e7d-605b-492b-9e96-e12477be384b</Output>
</ConnectedOutputs>
<BlendMode>Add</BlendMode>
<DisconnectedValue>0</DisconnectedValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Input>
<Input>
<UniqueID>b3f3d51c-1b1e-463a-8a79-4aa2ede5fb36</UniqueID>
<DefinitionID>fb2d8dc8-1e70-4303-aae7-048cc1e8462f</DefinitionID>
<DefaultName>Lag</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>False</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<BlendMode>Add</BlendMode>
<DisconnectedValue>0.755</DisconnectedValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Input>
</Inputs>
<Outputs>
<Output>
<UniqueID>e1d5772b-6cf3-4bb7-8175-30c9b411cea1</UniqueID>
<DefinitionID>a071aad5-93da-4a29-9d84-bd0d3f665a9b</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>False</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
</Outputs>
</Node>
<Node>
<UniqueID>45d6010c-2291-4018-84e8-3575cdd0525a</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName>4 Pin Ultrasonic Sensor</UserDefinedName>
<Description></Description>
<NodeColor>201,204,227,255</NodeColor>
<X>0</X>
<Y>0</Y>
<Width>546</Width>
<IncludeCode></IncludeCode>
<DeclerationCode>int echoPin = 8;
int trigPin = 7;
int maxPulse = 100; // Maximum micros to wait for a pulse
long duration;
float distance;</DeclerationCode>
<SetupCode>pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
</SetupCode>
<ImageName>arduino.png</ImageName>
<InfoURL></InfoURL>
<IsOpen>True</IsOpen>
<EditWidth>360</EditWidth>
<CodeDefinitions>
<CodeDefinition>
<UpdateCondition>EveryUpdate</UpdateCondition>
<Code>digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = (pulseIn(echoPin, HIGH)/2);
distance = float(duration*0.0343);
Output_Activation = transform(distance, 0, 300, 0.0, 1.0);
</Code>
<UniqueID>fcc85ffb-23db-45cc-84ef-ec0aa1a9103c</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs></Inputs>
<Outputs>
<Output>
<UniqueID>84297e7d-605b-492b-9e96-e12477be384b</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>
</EmbrioCopy>
EmbrioAdmin  
#13 Posted : Thursday, February 16, 2017 2:34:52 PM(UTC)
EmbrioAdmin

Rank: Administration

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

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Pay attention to the warning about sending a value for the timeout parameter in the pulseIn function. Embrio compiles a program by running a timing test on all nodes, then setting that amount of time aside on a time line for that node to execute. Things like pulseIn have a variable amount of time they take to execute, based on a physical issue it could pause for ever. To make sure the sensor node doesn't end up taking longer than the time reserved for it to run, you should try to figure out the max amount of time you'll need to wait for the pulseIn and pass that to the function.
FCazana  
#14 Posted : Friday, February 17, 2017 12:00:01 AM(UTC)
FCazana

Rank: Newbie

Groups: Registered
Joined: 2/14/2017(UTC)
Posts: 8

Ohh thank you very much, I will do test and I will change it.
leejames618  
#15 Posted : Sunday, July 30, 2017 6:11:26 PM(UTC)
leejames618

Rank: Newbie

Groups: Registered
Joined: 7/25/2017(UTC)
Posts: 6

I do not know if I did it right,
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