Examples | Shop
 
IRCM Network
 
This example application demonstrates the networking power of the IRCM’s (Infra Red Control Modules). Not only can you control the IRCM’s using a TV remote, but you can also communicate between IRCM modules themselves.
This example demonstrates how you can communicate from one Master IRCM plugged into an OOPic-R too two Slave IRCM (also plugged into OOPic-R modules).
This is only a small sample of the total networking ability of the IRCM’s. With a total of 256 possible nodes, this means the ability to communicate between 256 IRCM units!
In this example, the master IRCM/OOPic-R waits for button presses. When a button is pressed, data is sent too the two slave IRCM/OOPic-R which in turn, output to the equivalent LED IOLine. You can press any buttons you like and the information will be transferred from the master too the slaves.
This program could be used with a group of robots to form a ‘colony’. If one detects a disturbance, it will transmit a warning signal to all the other robots so all can react in the same way!
The only connection you need to make is to plug the IRCM onto the OOPic-R’s 5 way Programming Header (next to the DB9 port). The IRCM will only fit on one way.
Plug power to the OOPic-R boards and your network is up and running!
Download the code here.

 

'**************************************************************************
'**************************************************************************
'Example Application: IRCM Networking (IRCM Master)
'
'This example application demonstrates how to network between 3 OOPic-R's
'connected with IRCM modules. Press a button on the master OOPic-R/IRCM
'combination and the two slaves will respond by outputing the corresponding
'LED values on the OOPic-R's
'
'This code is the Master code.
'Created: 13/08/03
'Written by: Total Robots Ltd
'TR-IRCM-NET-MAS
'**************************************************************************
Dim IRCM As New oi2c 'Use I2C comms to IRCM
Dim Buttons As New oDio4 'The button Inputs
Dim WriteVal As New oByte 'Value to write to remote node
Dim LocNode As New oByte 'Local node address
Dim RemNode1 As New oByte 'Remote node address to write to
Dim RemNode2 As New oByte 'Remote node as address to write to
Dim ReadVal As New oByte 'Value read from remote node
Dim ReadAdr As New oByte 'Node address of remote node value came from
Dim Error As New oBit 'Error bit check
Dim OError As New oBit 'Error byte check
Dim ReadOK As New oBit 'Read value check
Dim Done As New oBit
Dim TOut As New oByte 'Timeout byte
'*************************************************************
Sub Main()

Buttons.IOGroup = 0 'Setup the button IOGroup
Buttons.Nibble = 1
Buttons.Direction = cvInput
oopic.delay = 400 'Wait 4 seconds for IRCM to initialise

LocNode = 1 'Define local node address (0-255)
RemNode1 = 2 'Define remote node address (0-255)
RemNode2 = 3 'Define second remote node address (0-255)
Const WriteTOut = 8 'Define write timeout in seconds (0-15)
Const IRCMAdr = &h60 'IRCM A & B pads OPEN (Range &h60-&h63)
Call SetUpIRCM 'Setup IRCM ready for communication
Do
WriteVal.Clear 'Clear write value
'*************************************************************
'This case select decides which button has been pressed and sends the
'corresponding value
'*************************************************************
Select Case Buttons.Value
Case 1: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 2: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 3: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 4: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 5: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 6: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
Case 7: WriteVal = Buttons.Value
do
Call WriteIRCM 'Perform remote node write
loop until Error = cvFalse 'until confirmed
End Select
Loop
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to setup I2C communication to DS-IRCM and
' set Local node address
'*************************************************************
Sub SetUpIRCM()
'Set the DS-IRCM I2C address shifted right by 1 bit
IRCM.Node = IRCMAdr 'Setup I2C address for IRCM
'Setup I2C addressing to IRCM
IRCM.Width = cv8bit 'Control Info is 1-byte
IRCM.Mode = cv10bit 'I2C mode is 10-Bit Addressing
IRCM.NoInc = cvFalse 'Increment on every read/write
IRCM.Location = 0 'Specifiy local node address location
IRCM.Value = LocNode 'and write local node address
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to write data to remote IRCM (RemNode) address
' On exit 'Error' = False if write completed OK
'*************************************************************
Sub WriteIRCM()
IRCM.Location = 1 'Start at remote node address
IRCM.Value = RemNode1 'Set remote node address to write to
IRCM.Value = WriteTOut 'Set write timeout value 1-15 seconds
IRCM.Value = WriteVal 'Send data to remote node
call WaitIRCM 'Wait for confirmation or error
IRCM.Location = 1 'Start at remote node address
IRCM.Value = RemNode2 'Set remote node address to write to
IRCM.Value = WriteTOut 'Set write timeout value 1-15 seconds
IRCM.Value = WriteVal 'Send data to remote node
call WaitIRCM 'Wait for confirmation or error
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to wait for confirmation that data has been successfully sent
' to the remote node or that a timeout error has occured
'*************************************************************
Sub WaitIRCM()
Done = cvFalse
do
IRCM.Location = 0 'Start at write completion status flag (R0)
If IRCM.Value = 255 then 'Has write been completed (R0) ?
If IRCM.Value = 0 then 'Has write resulted in error (R1) ?
Error = cvFalse 'Indicate no error has resulted
Done = cvTrue 'and request exit from sub-routine
else

Error = cvTrue 'If so then indicate error
Done = cvTrue 'and request exit from sub-routine
end if
else
If IRCM.Value = 255 then 'Has write resulted in error (R1) ?
Error = cvTrue 'If so then indicate error
Done = cvTrue 'and request exit from sub-routine
end if
end if
loop until Done = cvTrue
End Sub
'**************************************************************************

'**************************************************************************
'
'Example Application: IRCM Networking (IRCM Slave1)
'
'This example application demonstrates how to network between 3 OOPic-R's
'connected with IRCM modules. Press a button on the master OOPic-R/IRCM
'combination and the two slaves will respond by outputing the corresponding
'LED values on the OOPic-R's
'
'This code is the Slave1 code.
'Created: 13/08/03
'Written by: Total Robots Ltd
'TR-IRCM-NET-SLA1
'
'**************************************************************************
Dim IRCM As New oi2c 'Use I2C comms to IRCM
Dim LED As New oDio4 'The LED Outputs
Dim WriteVal As New oByte 'Value to write to remote node
Dim LocNode As New oByte 'Local node address
Dim RemNode1 As New oByte 'Remote node address to write to
Dim RemNode2 As New oByte 'Remote node as address to write to
Dim ReadVal As New oByte 'Value read from remote node
Dim ReadAdr As New oByte 'Node address of remote node value came from
Dim Error As New oBit 'Error bit check
Dim OError As New oBit 'Error byte check
Dim ReadOK As New oBit 'Read value check
Dim Done As New oBit
Dim TOut As New oByte 'Timeout byte
'**************************************************************************
Sub Main()

LED.IOGroup = 0 'Setup the LED IOGroup
LED.Nibble = 1
LED.Direction = cvOutput
oopic.delay = 400 'Wait 4 seconds for IRCM to initialise

LocNode = 2 'Define local node address (0-255)
RemNode1 = 1 'Define remote node address (0-255)
RemNode2 = 3 'Define second remote node address (0-255)
Const WriteTOut = 8 'Define write timeout in seconds (0-15)
Const IRCMAdr = &h60 'IRCM A & B pads OPEN (Range &h60-&h63)
Call SetUpIRCM 'Setup IRCM ready for communication

'*************************************************************
'This case select reads the IRCM and outputs the LED values depending on
'the received data from the master unit.
'*************************************************************
Do
Call ReadIRCM
Select Case ReadVal.Value
Case 1: LED.Value = ReadVal
Case 2: LED.Value = ReadVal
Case 3: LED.Value = ReadVal
Case 4: LED.Value = ReadVal
Case 5: LED.Value = ReadVal
Case 6: LED.Value = ReadVal
Case 7: LED.Value = ReadVal
End Select
Loop
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to setup I2C communication to DS-IRCM and
' set Local node address
'*************************************************************
Sub SetUpIRCM()
'Set the DS-IRCM I2C address shifted right by 1 bit
IRCM.Node = IRCMAdr 'Setup I2C address for IRCM
'Setup I2C addressing to IRCM
IRCM.Width = cv8bit 'Control Info is 1-byte
IRCM.Mode = cv10bit 'I2C mode is 10-Bit Addressing
IRCM.NoInc = cvFalse 'Increment on every read/write
IRCM.Location = 0 'Specifiy local node address location
IRCM.Value = LocNode 'and write local node address
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to check for data from remote IRCM(s) and upon
' confirmation that data has arrived store data in 'ReadVal' and
' remote IRCM address in 'ReadAdr'.
' On exit 'ReadOK' = True if data was read and 'OError' = True
' if internal data register has overflowed i.e. one or more data
' bytes may have been lost
'*************************************************************
Sub ReadIRCM()
IRCM.Location = 2 'Start at read status flag (R2)
If IRCM.Value = 255 then 'Has data been received (R2) ?
If IRCM.Value = 0 then 'If so has overflow error occured (R3) ?
ReadAdr = IRCM.Value 'If not then store IRCM address data came from
ReadVal = IRCM.Value 'and store data
OError = cvFalse 'Indicate no overflow error
ReadOK = cvTrue 'Indicate data has been read and stored
else
OError = cvTrue 'Indicate overflow error has occured
ReadOK = cvTrue 'Indicate data has been read
ReadAdr = IRCM.Value 'Store IRCM address data came from
ReadVal = IRCM.Value 'and store data
end if
else
OError = cvFalse 'If no data read then no error
ReadOK = cvFalse 'and no data
end if
End Sub
'**************************************************************************

'**************************************************************************
'
'Example Application: IRCM Networking (IRCM Slave2)
'
'This example application demonstrates how to network between 3 OOPic-R's
'connected with IRCM modules. Press a button on the master OOPic-R/IRCM
'combination and the two slaves will respond by outputing the corresponding
'LED values on the OOPic-R's
'
'This code is the Slave2 code.
'Created: 13/08/03
'Written by: Total Robots Ltd
'TR-IRCM-NET-SLA2
'
'**************************************************************************
Dim IRCM As New oi2c 'Use I2C comms to IRCM
Dim LED As New oDio4 'The LED Outputs
Dim WriteVal As New oByte 'Value to write to remote node
Dim LocNode As New oByte 'Local node address
Dim RemNode1 As New oByte 'Remote node address to write to
Dim RemNode2 As New oByte 'Remote node as address to write to
Dim ReadVal As New oByte 'Value read from remote node
Dim ReadAdr As New oByte 'Node address of remote node value came from
Dim Error As New oBit 'Error bit check
Dim OError As New oBit 'Error byte check
Dim ReadOK As New oBit 'Read value check
Dim Done As New oBit
Dim TOut As New oByte 'Timeout byte
'*************************************************************
Sub Main()

LED.IOGroup = 0 'Setup the LED IOGroup
LED.Nibble = 1
LED.Direction = cvOutput
oopic.delay = 400 'Wait 4 seconds for IRCM to initialise

LocNode = 3 'Define local node address (0-255)
RemNode1 = 2 'Define remote node address (0-255)
RemNode2 = 1
Const WriteTOut = 8 'Define write timeout in seconds (0-15)
Const IRCMAdr = &h60 'IRCM A & B pads OPEN (Range &h60-&h63)
Call SetUpIRCM 'Setup IRCM ready for communication

'*************************************************************
'This case select reads the IRCM and outputs the LED values depending on
'the received data from the master unit.
'*************************************************************
Do
Call ReadIRCM
Select Case ReadVal.Value
Case 1: LED.Value = ReadVal
Case 2: LED.Value = ReadVal
Case 3: LED.Value = ReadVal
Case 4: LED.Value = ReadVal
Case 5: LED.Value = ReadVal
Case 6: LED.Value = ReadVal
Case 7: LED.Value = ReadVal
End Select
Loop
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to setup I2C communication to DS-IRCM and
' set Local node address
'*************************************************************
Sub SetUpIRCM()
'Set the DS-IRCM I2C address shifted right by 1 bit
IRCM.Node = IRCMAdr 'Setup I2C address for IRCM
'Setup I2C addressing to IRCM
IRCM.Width = cv8bit 'Control Info is 1-byte
IRCM.Mode = cv10bit 'I2C mode is 10-Bit Addressing
IRCM.NoInc = cvFalse 'Increment on every read/write
IRCM.Location = 0 'Specifiy local node address location
IRCM.Value = LocNode 'and write local node address
End Sub
'**************************************************************************

'*************************************************************
' Subroutine to check for data from remote IRCM(s) and upon
' confirmation that data has arrived store data in 'ReadVal' and
' remote IRCM address in 'ReadAdr'.
' On exit 'ReadOK' = True if data was read and 'OError' = True
' if internal data register has overflowed i.e. one or more data
' bytes may have been lost
'*************************************************************
Sub ReadIRCM()
IRCM.Location = 2 'Start at read status flag (R2)
If IRCM.Value = 255 then 'Has data been received (R2) ?
If IRCM.Value = 0 then 'If so has overflow error occured (R3) ?
ReadAdr = IRCM.Value 'If not then store IRCM address data came from
ReadVal = IRCM.Value 'and store data
OError = cvFalse 'Indicate no overflow error
ReadOK = cvTrue 'Indicate data has been read and stored
else
OError = cvTrue 'Indicate overflow error has occured
ReadOK = cvTrue 'Indicate data has been read
ReadAdr = IRCM.Value 'Store IRCM address data came from
ReadVal = IRCM.Value 'and store data
end if
else
OError = cvFalse 'If no data read then no error
ReadOK = cvFalse 'and no data
end if
End Sub
'**************************************************************************
'**************************************************************************


Examples | Shop