Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
gary.thom@afulki.com  
#1 Posted : Thursday, April 09, 2015 6:17:38 AM(UTC)
Afulki

Rank: Member

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

Thanks: 2 times
Using the I2C write module, I created a port expander, however I would like a better way of passing binary values, currently using strings (text input) but having trouble constructing the strings to pass,

<Nodes>
<Node>
<UniqueID>6d68450d-4a6e-412d-8f8e-54478664e8ce</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName>I2C Write</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>686</Width>
<IncludeCode>#include &quot;Wire.h&quot;</IncludeCode>
<DeclerationCode></DeclerationCode>
<SetupCode>Wire.begin(); // join i2c bus (address optional for master)
Wire.beginTransmission(0x20);
Wire.write(0x00); // IODIRA register
Wire.write(0x00); // set all of port A to outputs
Wire.endTransmission();
Wire.beginTransmission(0x20);
Wire.write(0x01); // IODIRB register
Wire.write(0x00); // set all of port A to outputs
Wire.endTransmission();
</SetupCode>
<ImageName></ImageName>
<InfoURL>http://embrio.io/custom-arduino-nodes/outputs/i2c-write</InfoURL>
<CodeDefinitions>
<CodeDefinition>
<TriggerInputID>5560208e-611d-4622-8cf7-4a083565b2e4</TriggerInputID>
<UpdateCondition>Trigger</UpdateCondition>
<Code>Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.write((byte) strtoul(Input_PortA.c_str(), 0, 16));
Wire.endTransmission();

Wire.beginTransmission(0x20);
Wire.write(0x13);
Wire.write((byte) strtoul(Input_PortB.c_str(), 0, 16));
Wire.endTransmission();
</Code>
<UniqueID>c4932317-e31a-49d6-8cf1-cee6229a844e</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs>
<Input>
<UniqueID>b1f15f38-fa7c-4554-a387-556da9fa2e34</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text</DefaultName>
<CustomName>PortA</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue></DisconnectedValue>
<MaxLength>4</MaxLength>
</Input>
<Input>
<UniqueID>b4d7585f-f7cf-40e3-8587-d68988e2a40c</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text 1</DefaultName>
<CustomName>PortB</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue></DisconnectedValue>
<MaxLength>4</MaxLength>
</Input>
<Input>
<UniqueID>5560208e-611d-4622-8cf7-4a083565b2e4</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Trigger</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Trigger</TypeName>
<IsOutsideConnection>True</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></Outputs>
</Node>
</Nodes>
EmbrioAdmin  
#2 Posted : Thursday, April 09, 2015 6:24:09 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)
I'm not too familiar with the problem you are solving. Could you give me an example of how you'd want to use that node and what the byte values would be? This might require a new feature but I don't know enough about what you're trying to do yet.
gary.thom@afulki.com  
#3 Posted : Thursday, April 09, 2015 6:43:28 AM(UTC)
Afulki

Rank: Member

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

Thanks: 2 times
Hi,

The chip takes a byte to control the 8 I/O lines 0X00 - 0XFF which really doesn't map well to 0.0 - 1.0 if you want to control individual bits.

So, I created a tex input for each port, that takes a 4 character string in the form "0X00" etc.

I'm wondering how to generate the input text that would be sent to the Text property. Say for example say the arduino is monitoring 8 switches, and I wanted each to control an output on the port expander, I would need some way of combining all 8 inputs, and outputting a text representation of the byte value to send to the controller.

Not sure if I'm being clear?
EmbrioAdmin  
#4 Posted : Thursday, April 09, 2015 6:51:10 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)
I think something like this might help (open the spoiler for the xml, trying to keep things relatively clean).

It uses one text activation node per byte code, connect them all to the text input, then use some kind of control structure to only activate one at a time, in this case a multi-step node. Would something like this work for what you're trying to do?

gary.thom@afulki.com  
#5 Posted : Thursday, April 09, 2015 7:02:05 AM(UTC)
Afulki

Rank: Member

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

Thanks: 2 times
Thanks for the quick reply, I'm not sure how efficient that would be, I would need 255 output strings and map 8 inputs to them.

To me a new math function would suffice, or perhaps a custom math function, hmm. I might just try that. :)

EmbrioAdmin  
#6 Posted : Thursday, April 09, 2015 7:07:43 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're right that would be very inefficient, especially considering it would take 4 bytes of memory per byte... Let me know if you come up with something. This might call for a new built in node, but I don't really understand well enough what the inputs to that node would be. If you come up with something I'd appreciate if you sent me the project so I could better understand it and maybe come up with a special node that does this sort of I2C stuff.
gary.thom@afulki.com  
#7 Posted : Thursday, April 09, 2015 7:38:00 AM(UTC)
Afulki

Rank: Member

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

Thanks: 2 times
I've only been using Embrio for about 24 hours, I like what I see, my main issue is bridging between ladder / SCADA type logic as implemented using the activation / suppression and binary / data driven.

The controller I'm trying to create would be interfaced with relays, now if I were wring the relays directly to an IO pin, then the Agent model works, but in my case a single agent needs to represent a block of IO pins, i.e. 2 ports, with 8 pins each on the IC connected via the I2C bus.

Take a more concrete example:

Say I wanted to create a simple irrigation system, where the 8 pins on a single port controlled 8 relays controlling 8 valves. Say also that I want to have things happen at a specific time of day, and for a duration. This type of application is responding to external events, i.e. button presses (though a UI associated with it might), it is generating its own events based on data and time.

I can see no simple way of setting up an agent that combines the 16 bits of data into two bytes to be sent to the I2C (even splitting this into two agents, one per port) would mean exposing 8 Activators (0 or 1) then using code to combine them.

If there was an additional input type that could represent a number (integer or byte or word) that could be passed to other agents that would then open the door to having math agents that worked on binary and/or integer values.

EmbrioAdmin  
#8 Posted : Thursday, April 09, 2015 8:39:30 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)
I'm imaging a node with 8 input toggle triggers or activations that sends a byte via i2c. In the case or activation inputs 0 would be off all other values on. We're you thinking of a node with 8 inputs and one output that is a byte you'd send to an arduino node? I feel like adding more data types might make things more confusing and go against the philosophy of the software, but it might be necessary to add flexibility.
thanks 1 user thanked EmbrioAdmin for this useful post.
Afulki on 4/9/2015(UTC)
gary.thom@afulki.com  
#9 Posted : Thursday, April 09, 2015 9:25:04 AM(UTC)
Afulki

Rank: Member

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

Thanks: 2 times
I think I have what I need for now, created an agent with 8 inputs corresponding to the pins, and it merges the value in code, seems to work and I can create a 2nd one for the other port, it doesn't seem to mind having 2 Wire.begins().

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