Serial port IO module with 15 inputs

From uCtrl
This page is kept for historical interest. It may document projects or methods that are obsolete and/or no longer relevant. The information here is not kept up-to-date.

This module was part of the rack box project — which was terminated when I moved out of my first apartment.
Serial port IO module installed in the rack box

Information

OMU2 is connected to a computer serial port, and reports the status of 15 inputs. If a input is activated the unit sends the status to the computer instantly, each input has a timeout of three seconds. It's also possible to request the status of any input at any given time. Every 20th second a life pulse is sent to Serial Server.

After the Rack box project was terminated, this project was rebuilt into Temperature and humidity sensor (RS232).

I/O

Inputs

  1. PC0 In 1
  2. PC1 In 2
  3. PC2 In 3
  4. PC3 In 4
  5. PC4 In 5
  6. PC5 In 6
  7. PD3 In 7
  8. PD4 In 8
  9. PD5 In 9
  10. PD6 In 10
  11. PD7 In 11
  12. PB2 In 12
  13. PB3 In 13
  14. PB4 In 14
  15. PB5 In 15

Outputs

  1. PB0 Lifesignal (to Module stability monitoring unit 2)
  2. PB1 Link activity LED

Interface

  • PD0 RS-232 Rx
  • PD1 RS-232 Tx

Connectors

Wires

Red
5V
White
0V
Green
Lifesignal

15-pin

  1. In 1
  2. In 2
  3. In 3
  4. In 4
  5. In 5
  6. In 6
  7. In 7
  8. In 8
  9. In 9
  10. In 10
  11. In 11
  12. In 12
  13. In 13
  14. In 14
  15. In 15

9-pin

  • 2 Transmit
  • 3 Receive
  • 5 GND

Communication

Interfacing is done with RS-232, using MAX232 or MAX202.

001:i:02:1:116 'in 2 on                                                                
001:i:01:1:115 'in 1 on 
001:i:02:0:116 'in 2 off                                                                
001:i:01:0:115 'in 1 off
001:s:01:1:126 'lifesignal                                                                  

Serial settings

Baud
9600
Data bits
8
Parity
None
Stop bits
1
Start command
0
Module ID
001

Images

Schematic drawing

Omu2 circuit.png

Parts list

Qty. Part
1 AVR ATmega8-16PU, DIL-28, 16 MHz, 23 I/Os
5 Capacitor, aluminium electrolytic, 1 µF, 50V
1 Capacitor, aluminium electrolytic, 10 µF, 25V
1 Capacitor, ceramic, 1 nF, 100V
2 Capacitor, metallized polyester foil, 0.01 µF
1 D-Sub soldering cups, 15 pin male
1 D-Sub soldering cups, 9 pin female
1 DIL socket, 16-pin, 7.62mm
1 DIL socket, 28-pin, 7.62mm
1 Enclosure, plastic (1591 FL), 120x65x40mm, flange
1 Fuse 5x20 mm, 200 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
1 LED 5mm clear, Yellow, 2.0V, 20mA, 250mcd, 6°
1 LED 5mm coloured clear, Green, 2.1V, 20mA, 30mcd, 10°
2 LED holder 5mm, RTC51, black plastic
2 Mounting bracket, DIN rail, Plastic
32 cm2 PCB, stripboard, 100x160mm, 160cm2
17 Resistor, carbon film, 0.25W, 330 Ω, 5%
2 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
15 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 RS232 interface, MAX232CPE, dual
22 Straight pin header, female, Single row, 2.54mm
30 Straight pin header, male, Single row, 2.54mm
1 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_OMU_v.2.0
' date: 25/09/2008
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Input
Config Portb.3 = Input
Config Portb.4 = Input
Config Portb.5 = Input
Config Portc = Input
Config Portd.3 = Input
Config Portd.4 = Input
Config Portd.5 = Input
Config Portd.6 = Input
Config Portd.7 = Input

Dim Lifesignal As Integer , Life As Integer , Send As String * 15
Dim Inn(15) As Integer , A As Byte , A2 As String * 1
Dim Serialcharwaiting As Byte , Serialchar As Byte
Dim Comminput As String * 15 , Input_nr As String * 3
Dim Input_com As String * 1 , Input_ut As String * 2
Dim Led As Byte

Const Id = "001"
Life = 2000

Waitms 5000

Top:

Serialcharwaiting = Ischarwaiting()

If Serialcharwaiting = 1 Then
   Serialchar = Inkey()
      Goto Myroutine
   End If

Goto Main

Myroutine:
Select Case Serialchar
Case 48 '0
Goto Set_value
End Select

Main:
'input send off signal
For A = 1 To 15
   If Inn(a) = 1 Then
      Led = 103
      A2 = Str(a)
      If Len(a2) < 2 Then A2 = "0" + A2
      Send = Id + ":i:" + A2 + ":0:"
      Print Send ; Checksum(send)
      End If
Next A

'send on signal
If Pinc.0 = 0 Then 'input 1
   If Inn(1) = 0 Then
   Led = 103
   Send = Id + ":i:01:1:"
   Print Send ; Checksum(send)
   End If
   Inn(1) = 3000
End If

If Pinc.1 = 0 Then 'input 2
   If Inn(2) = 0 Then
   Led = 103
   Send = Id + ":i:02:1:"
   Print Send ; Checksum(send)
   End If
   Inn(2) = 3000
End If

If Pinc.2 = 0 Then 'input 3
   If Inn(3) = 0 Then
   Led = 103
   Send = Id + ":i:03:1:"
   Print Send ; Checksum(send)
   End If
   Inn(3) = 3000
End If

If Pinc.3 = 0 Then 'input 4
   If Inn(4) = 0 Then
   Led = 103
   Send = Id + ":i:04:1:"
   Print Send ; Checksum(send)
   End If
   Inn(4) = 3000
End If

If Pinc.4 = 0 Then 'input 5
   If Inn(5) = 0 Then
   Led = 103
   Send = Id + ":i:05:1:"
   Print Send ; Checksum(send)
   End If
   Inn(5) = 3000
End If

If Pinc.5 = 0 Then 'input 6
   If Inn(6) = 0 Then
   Led = 103
   Send = Id + ":i:06:1:"
   Print Send ; Checksum(send)
   End If
   Inn(6) = 3000
End If

If Pind.3 = 0 Then 'input 7
   If Inn(7) = 0 Then
   Led = 103
   Send = Id + ":i:07:1:"
   Print Send ; Checksum(send)
   End If
   Inn(7) = 3000
End If

If Pind.4 = 0 Then 'input 8
   If Inn(8) = 0 Then
   Led = 103
   Send = Id + ":i:08:1:"
   Print Send ; Checksum(send)
   End If
   Inn(8) = 3000
End If

If Pind.5 = 0 Then 'input 9
   If Inn(9) = 0 Then
   Led = 103
   Send = Id + ":i:09:1:"
   Print Send ; Checksum(send)
   End If
   Inn(9) = 3000
End If

If Pind.6 = 0 Then 'input 10
   If Inn(10) = 0 Then
   Led = 103
   Send = Id + ":i:10:1:"
   Print Send ; Checksum(send)
   End If
   Inn(10) = 3000
End If

If Pind.7 = 0 Then 'input 11
   If Inn(11) = 0 Then
   Led = 103
   Send = Id + ":i:11:1:"
   Print Send ; Checksum(send)
   End If
   Inn(11) = 3000
End If

If Pinb.2 = 0 Then 'input 12
   If Inn(12) = 0 Then
   Led = 103
   Send = Id + ":i:12:1:"
   Print Send ; Checksum(send)
   End If
   Inn(12) = 3000
End If

If Pinb.3 = 0 Then 'input 13
   If Inn(13) = 0 Then
   Led = 103
   Send = Id + ":i:13:1:"
   Print Send ; Checksum(send)
   End If
   Inn(13) = 3000
End If

If Pinb.4 = 0 Then 'input 14
   If Inn(14) = 0 Then
   Led = 103
   Send = Id + ":i:14:1:"
   Print Send ; Checksum(send)
   End If
   Inn(14) = 3000
End If

If Pinb.5 = 0 Then 'input 15
   If Inn(15) = 0 Then
   Led = 103
   Send = Id + ":i:15:1:"
   Print Send ; Checksum(send)
   End If
   Inn(15) = 3000
End If '

'set input counters
For A = 1 To 15
   If Inn(a) > 0 Then Decr Inn(a)
Next A

'led timer
If Led > 0 Then Decr Led
If Led = 100 Then Portb.1 = 1
If Led = 0 Then Portb.1 = 0

'lifestring
If Life > 0 Then Decr Life
If Life = 0 Then
   Led = 103
   Send = Id + ":s:01:1:"
   Print Send ; Checksum(send)
   Life = 20000
   End If

'lifesignal
If Lifesignal > 0 Then Decr Lifesignal
If Lifesignal = 500 Then Portb.0 = 1
If Lifesignal = 0 Then
   Portb.0 = 0
   Lifesignal = 2100
   End If

'loop cycle
Waitms 1
Goto Top
End

Set_value:
Input Comminput Noecho 'read serialport

Input_nr = Left(comminput , 3) 'id check
Input_com = Mid(comminput , 5 , 1) 'command check
Input_ut = Mid(comminput , 7 , 2) 'output nr check

If Input_com = "i" And Input_nr = Id Then
Select Case Input_ut

Case "01"
If Inn(1) = 0 Then Inn(1) = 2 Else Inn(1) = 0 'status input 1
Case "02"
If Inn(2) = 0 Then Inn(2) = 2 Else Inn(2) = 0 'status input 2
Case "03"
If Inn(3) = 0 Then Inn(3) = 2 Else Inn(3) = 0 'status input 3
Case "04"
If Inn(4) = 0 Then Inn(4) = 2 Else Inn(4) = 0 'status input 4
Case "05"
If Inn(5) = 0 Then Inn(5) = 2 Else Inn(5) = 0 'status input 5
Case "06"
If Inn(6) = 0 Then Inn(6) = 2 Else Inn(6) = 0 'status input 6
Case "07"
If Inn(7) = 0 Then Inn(7) = 2 Else Inn(7) = 0 'status input 7
Case "08"
If Inn(8) = 0 Then Inn(8) = 2 Else Inn(8) = 0 'status input 8
Case "09"
If Inn(9) = 0 Then Inn(9) = 2 Else Inn(9) = 0 'status input 9
Case "10"
If Inn(10) = 0 Then Inn(10) = 2 Else Inn(10) = 0 'status input 10
Case "11"
If Inn(11) = 0 Then Inn(11) = 2 Else Inn(11) = 0 'status input 11
Case "12"
If Inn(12) = 0 Then Inn(12) = 2 Else Inn(12) = 0 'status input 12
Case "13"
If Inn(13) = 0 Then Inn(13) = 2 Else Inn(13) = 0 'status input 13
Case "14"
If Inn(14) = 0 Then Inn(14) = 2 Else Inn(14) = 0 'status input 14
Case "15"
If Inn(15) = 0 Then Inn(15) = 2 Else Inn(15) = 0 'status input 15

End Select

End If
Goto Main
End