Jump to content
Sign in to follow this  

Serial Pressure Floor Mat (Halloween Project)

Recommended Posts


I picked up an older Pressure Floor Mat that use to be connected to a Wyse device and functioned as a auto logon / logoff switch for a kiosk. I have been working with the CommMG UDF's, with no luck. I installed a serial monitor program and still can't seem to communicate with the floor pad. A serial port was a bit difficult to locate, I currently have the floor mat connected to the docking station of the laptop.

Project: Play short video when the Pressure Floor Mat is stepped on.


Share this post

Link to post
Share on other sites

OK, So I picked up a Sabrent USB 2.0 to serial adapter. I am assuming that I will need to be listening on Com4 with default settings 9600 ect... I have never scripted anything for this type of project, My thought was to monitor the com4 port and jump on the pad and see what information I can gather, then script something to listen on the port and play video when someone steps on the mat. If someone could point me in the right direction of what I am trying to do, I can write the code, please help!

Share this post

Link to post
Share on other sites


Arduino Section

I bought an Arduino UNO with some jumper wires off Amazon for $15. I downloaded and installed the Arduino software. I tried using the  built in Digital Button example included with the Arduino software. I didn't have the proper resistor, however I connected jumper wires to PIN 5 to ground and PIN 2 to digital 2. When I tested the mat, the on-board LED would light up and it would light up randomly as well. After doing some research I found the following link that explained I was getting noise interference causing the code to randomly trigger http://www.instructables.com/id/Arduino-Button-Tutorial/

// Arduino button tutorial 1.
// Demonstrates:
// - detection of pressing state
// Push-button must be connected as follows:
//              __,__
//   Pin2 ------o   o------ GND
// (C) 2011 By P. Bauermeister
// This example code is in the public domain.

// Adapt these to your board and application timings:

#define BUTTON_PIN        2  // Button
#define DELAY            20  // Delay per loop in ms


void setup()
  digitalWrite(BUTTON_PIN, HIGH); // pull-up

boolean handle_button()
  int button_pressed = !digitalRead(BUTTON_PIN); // pin low -> pressed
  return button_pressed;

void loop()
  // handle button
  boolean button_pressed = handle_button();

  // do other things
  Serial.print(button_pressed ? "1" : "0");

  // add newline sometimes
  static int counter = 0;
  if ((++counter & 0x3f) == 0)


I loaded the above (slightly modified) code to the Arduino, connected jumper wires to PIN 5 to ground and PIN 2 to digital 2, stepped on the pad and magic happened.

Autoit Section

I downloaded the CommMG.au3 UDF and the commg.dll, however I couldn't get anything working, Why?!?!?! cause I was running a 64 bit version of windows. I installed Virtual Box and created a 32 bit VB and tested the again and magic happened.

#include <arduino.au3>
#include <GUIConstants.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <CommMG.au3>

Local $convar = False

_CommSetDllPath(@ScriptDir & "\commg.dll")

$gui = GUICreate ("Arduino serial connections",500)
$inut = GUICtrlCreateEdit("",10,60,200,300)
$output = GUICtrlCreateEdit("",270,60,200,300,$ES_READONLY)
$send = GUICtrlCreateButton("Send to Arduino",20,20)
$ports = GUICtrlCreateCombo("",155,22)
GUICtrlCreateLabel("Ports:" ,120,24)
$connect = GUICtrlCreateButton(" Connect COM ",260,20)
$disconnect = GUICtrlCreateButton (" Disconnect COM ",370,20)
GUICtrlCreateLabel("Send edit",50,370)
GUICtrlCreateLabel("Recieve edit",330,370)

While 1
Switch GUIGetMsg()
    Case $connect
       $ported = GUICtrlRead($ports)
       MsgBox ("","","Connected to :" &$ported)
       $convar = True

    Case $disconnect
        MsgBox ("","","COM Disconnected")
        $convar = False


     Case $send
         If $convar Then
         $sended = GUICtrlRead($inut)
         MsgBox ("","","String Send")
         MsgBox ("","","Please connect to COM before sending data to it")

$inpcom = _CommGetstring()

If Not @error And StringLen($inpcom) > 0 And $inpcom <> 0 Then SplashTextOn("YOUR STANDING ON THE MAT","PLAY VIDEO","-1","-1","-1","-1",32,"Impact","36","700")
If Not @error And StringLen($inpcom) > 0 And $inpcom <> 1 Then SplashOff()

The above code is slightly modified and was used for testing to make sure everything was working.

Edited by nlgma

Share this post

Link to post
Share on other sites

have you tried running the 32 bit version of AutoIt on your 64 bit Windows? By default, you're probably running AutoIt_64.exe.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Inpho
      Hi All,
      I didn't know where to put this; my apologies if this is the wrong location.
      When you plug a Samsung mobile device (phone, tablet, etc.) into the USB of a Windows PC, you can right-click the device in My Computer and select Properties. Here, it will show you the correct serial number of the device. Clearly Windows doesn't use adb to get the SN so I'm stuck at how to get the SN without adb and where the device doesn't have a drive letter assigned to it.
      When I last picked this up, I tried seemingly everything I could from wmi(?) and winmgmts(?) but either it's hidden cloak-and-dagger style or I can't see the forest for the trees...
      Does anyone know what API Windows uses when getting the serial number of a device Windows calls a Portable Media Player?

    • By MazeM
      here's another UDF for the serial port. It is very similar to CommAPI using kernel32.dll, but all code is packed into a single file without any dependencies, not even using WinAPI.au3. It differs from existing UDF that it doesn't allow a timeout when reading, instead it always returns immediately, either with the requested amount ob bytes read or with a failure status. And of course there is a function provided to query the amount of available bytes in the receive buffer. The reason behind this design decision: You can do 1000 other things in the main loop while checking from time to time if enough data bytes arrived. There's no point to block the program waiting for the serial port.
      It is currently a work-in-progress, as I didn't test all functions yet. The code was developed and tested on Windows 7 64 bit.  The ComUDF-Tests.au3 shows some tests and basic usage of the UDF. Maybe there's no reason to use this UDF, given the existence of the others UDFs, but I did it to get to know DllCall better - I use structs no only to pass but also to get data back (I don't use the array returned by DllCall to read that data, unless required). You're welcome to test it on older and newer Windows versions.
      Here's a list of the implemented functions:
      ; _ComListPorts ; _ComOpenPort ; _ComSetTimeouts ; _ComClosePort ; ; _ComSetBreak ; _ComClearBreak ; _ComGetInputcount ; _ComGetOutputcount ; _ComClearOutputBuffer ; _ComClearInputBuffer ; ; _ComSendByte ; _ComReadByte ; _ComSendBinary ; _ComReadBinary ; ; _ComSendChar ; _ComReadChar ; _ComSendCharArray ; _ComReadCharArray ; _ComSendString ; _ComReadString ; ; __ComClearCommError ; __PurgeComm Maze
    • By Satvik
      I am trying to open a dll using DLLOpen, however everytime i try to do so the function fails and returns -1 result. 
      I have the dll in the same folder as the auto it script. 
      Local $hDLL = DllOpen("C:\Users\310255155\Downloads\COMMGvv2\commg.dll") DllCall($hDLL, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) DllClose($hDLL) MsgBox(0,'result',$hDLL)  
    • By dainiusb
      So I'm trying to send a string of data to Arduino using CommMG UDF. It seems that Arduino is not receiving it. I used Device Monitoring Studio and it shows that the data is sent fine and looks exactly the same as if I sent it from Arduino Serial Monitor. Is CommMG compatible with USB?
      Global $CMPort = 9 Global $CmBoBaud = 9600 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 1 Global $setflow = 2 _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then MsgBox(16,"Error!","Can't connect to Arduino on port - "&$CMPort) Exit EndIf _CommSetRTS(0) _CommSetDTR(0) _CommSendString("x" & 128 & "y" & 256 & "e", 1)  
    • By toasterking
      I was just working on a project that involved decoding a stream of binary data from a serial port in AutoIt.  It took me a few hours to figure out how to process the data efficiently in AutoIt and I did not find any helpful examples on how to do so, so I thought I would share my core example and maybe save someone else some time.  There may be a more efficient way to do this, but this works well for me.
      #cs Author: ToasterKing This is an example of a way to parse streaming binary data that follows a strict format with a header and footer. In this example, each frame is 5 bytes with a 2-byte header of 0xD5AA and a 1-byte footer of 0xAD. The _BinaryParse() function accumulates incoming data in a buffer. Once a footer is found, it searches backward for the header, and if it is in the right position, it extracts the remaining 2 bytes in the middle, then moves on to looking for the next frame. #ce ; The data source might be something asynchronous like serial or TCP, but since this is just an example, I'm just putting the data in a variable. Local $fSomeData $fSomeData = Binary("0xD5AA24B1") ; Binary data constituting almost a complete frame. _BinaryParse($fSomeData) ; Call the function with the received data. It isn't a complete frame, so it is just stored in the buffer until more data is received. $fSomeData = Binary("0xAD62D5AA92E7AD") ; Remainder of the previous frame, one garbage byte (0x62) which should be skipped, and a complete additional frame. _BinaryParse($fSomeData) ; The function should be able to parse both frames now. Func _BinaryParse($fNewData) Local Static $fBinaryReceived = Binary("") ; Buffer for received data ConsoleWrite("Hey, the function is called!" & @CRLF) ; Add new data to the buffer. ; This ridiculous monstrosity is the only way I could find to append binary data to binary data in AutoIt. It must be converted to strings first. ; Both, one, or no substrings will begin with "0x" depending on whether they contained binary data. To be converted back to binary properly, only one instance ; of "0x" must exist at the beginning of the string. $fBinaryReceived = Binary("0x" & StringReplace(String($fBinaryReceived) & String($fNewData),"0x","")) ConsoleWrite("Data in the buffer: " & String($fBinaryReceived) & @CRLF) Local $iLength = BinaryLen($fBinaryReceived) ; Count the bytes in the data If $iLength > 0 Then Local $fBinaryReceivedTemp = $fBinaryReceived ; Create temporary copy to work on Local $fByte1,$fByte2 For $i = 1 To $iLength If BinaryMid($fBinaryReceivedTemp,$i,1) = 0xAD Then ; If the 1-byte footer found ConsoleWrite("Footer found at end of " & $i & " of " & $iLength & " bytes!" & @CRLF) If BinaryMid($fBinaryReceivedTemp,$i - 4,1) = 0xD5 And BinaryMid($fBinaryReceivedTemp,$i - 3,1) = 0xAA Then ; and the 2-byte header is found 4 bytes before that ConsoleWrite("Header found before the footer!" & @CRLF) $fByte1 = BinaryMid($fBinaryReceivedTemp,$i - 2,1) ; Get 1st byte in the body (between header and footer) $fByte2 = BinaryMid($fBinaryReceivedTemp,$i - 1,1) ; Get 2nd byte in the body (between header and footer) ConsoleWrite("Here is the critical data: " & String($fByte1) & " " & String($fByte2) & @CRLF) ; Just display the 2 bytes for demonstration purposes. Normally, you'd do something more useful with it here. EndIf $fBinaryReceived = BinaryMid($fBinaryReceivedTemp,$i + 1) ; Truncate the original data to remove all of the bytes just processed, then continue processing $fBinaryReceivedTemp EndIf Next EndIf EndFunc  
  • Create New...