Matrix MI3932 MIAC AllCode Getting Started Manual Download Page 12

Page 12 

Copyright © 2017 Matrix Technology Solutions Limited 

www.matrixtsl.com

 

 

 

Bluetooth setup 

Raspberry Pi and Linux

 

The Raspberry Pi is a popular single-board computer. 
 
The most common operating system used on the 
Raspberry Pi is a variety of Linux called Raspbian. 
 
The instructions here for pairing the MIAC AllCode are 
not limited to a Raspberry Pi and should apply to most 
Linux-based computers.

 

Setting up Bluetooth is relatively easy on a Raspberry Pi and can be done in a number of 
ways. The following steps are perhaps a more complex way of setting it up, but it should 
work in all situations. Note the Pi needs a Bluetooth USB dongle. 
 

Step 1 – Get your Bluetooth settings 

Open a command-line terminal and type the command “hciconfig”. This will bring up a list 
of Bluetooth devices available on your RPi. The important thing to note is the identifier of 
the Bluetooth module – in my case it is “hci0”: 
 
 
 
 

 
Step 2 – Detect the MIAC AllCode  

Switch on the MIAC and then type “hcitool scan”. When I did this, it showed two devices. 
Mine was the latter (“API_B”) and you will need to take note of the 6 pairs of hexadecimal 
numbers that are the MAC address, a unique identifier to the MIAC  – in my case, 
 
 
 
 
 
“00:BA:55:23:1C:20”. 
 
 
 
 
 

Step 3 – Pair the MIAC with the RPi 

To pair, you can use the “bluez-simple-agent” command using the “hci0” and MAC 
address found in the previous steps.

 

MIAC AllCode 
Instructional Guide

 

Summary of Contents for MI3932 MIAC AllCode

Page 1: ......

Page 2: ...tooth Setup Android Tablet Phone 10 Bluetooth Setup Raspberry Pi and Linux 12 WIFI Setup Connecting to the IP Address 14 Controlling The MIAC Using Flowcode 15 Controlling The MIAC Using App Inventor 17 Controlling The MIAC Using C C VB 20 Controlling The MIAC Using Python 22 Controlling The MIAC Using Labview 24 Transistor Outputs Using PWM 25 API Documentation Input and Output 26 API Documentati...

Page 3: ... device to the MIAC The Bluetooth enabled MIAC AllCode must be paired to your Bluetooth enabled device to allow API communications to work correctly Pages 8 through 13 show how to pair the MIAC AllCode to various different devices Connecting the MIAC AllCode to your WIFI network The WIFI enabled MIAC AllCode can be connected to your WIFI network by using the configuration menu when powering up the...

Page 4: ...c operation MIAC AllCode Instructional Guide Analog Digital Inputs x 8 Relay Outputs x 4 Normally Open Mains Rated Transistor Outputs x 4 High Speed 2 x DC motor Full H Bridge Graphical Display with Backlight 9 Button Keypad Reset Switch and USB Socket Bluetooth WIFI communications module Internally Fitted DIN Rail Mounting Screw Hole Mounting CAN Bus Communications Serial RS232 RS485 Communicatio...

Page 5: ...es out the required function If for some reason the TV remote failed it would be an easy task to replace it with a new one or even purchase a universal remote if you had a number of devices to control There are Apps that can be used to turn smart phones into a TV remote controller and other hardware is available that can send out TV remote codes The only critical part is to send the correct patter...

Page 6: ...llowed by one or more parameters Depending on what you are trying to do with the MIAC these parameters can be numerical or textual or a mixture of both For example to send a value to the four relays on the MIAC you would use WriteRelays value As the relays are grouped together and form an 4 bit row they can be driven by sending a binary number to them So the parameter value can take a value betwee...

Page 7: ...nteract with the MIAC AllCode The name of these calls will map across to the set of macros available in Flowcode AppInventor Python and other languages supported by the MIAC AllCode A full list of available API calls is available at the end of this document Using pseudo code allows you to take the first step of putting your ideas into practice in a structured way without getting tripped up by the ...

Page 8: ...eds to be switched on using a special switch or function key Please consult your PC or Windows help for more information 2 Pair the MIAC First switch on the MIAC the Bluetooth device name pair key and visibility can be checked and edited using the Configure menu and then selecting Bluetooth Settings when powering up the MIAC Again pairing works slightly differently on the various Windows versions ...

Page 9: ...ow as shown on the right There are two COM ports listed for each MIAC Make sure you always use the outgoing port number This window can be a bit hard to find on some versions of Windows For example on Windows 10 you can find this via the More Bluetooth options link on the Bluetooth settings screen Luckily there is a guaranteed way of opening this window in all versions of Windows from version 7 Op...

Page 10: ... built in then you may first have to enable it by clicking on Settings Connections Once Bluetooth is enabled you need to pair the MIAC AllCode to your phone to allow Apps to see the device Begin by clicking the Bluetooth option in Settings Connections Next make sure your MIAC is switched on and click the Scan button on your Android device to check for new Bluetooth devices Note you may have to scr...

Page 11: ... will be asked to enter the pair key The default key is 1234 Once the device is paired it will be listed along with any other paired Bluetooth devices you might have and is ready to be used with any MIAC AllCode apps you download or create Please note This may be subtly different on your Android device For specifics on your Phone or Tablet please look up how to pair Bluetooth devices for your spec...

Page 12: ...ll situations Note the Pi needs a Bluetooth USB dongle Step 1 Get your Bluetooth settings Open a command line terminal and type the command hciconfig This will bring up a list of Bluetooth devices available on your RPi The important thing to note is the identifier of the Bluetooth module in my case it is hci0 Step 2 Detect the MIAC AllCode Switch on the MIAC and then type hcitool scan When I did t...

Page 13: ...will use the MAC address found in step 2 and can use the name in the comment field If you have more than one MIAC you can add multiple sections just name each one rfcomm1 rfcomm2 etc Step 5 Testing the connection Once you are paired you can test the connection by using the following in the command line terminal echo WriteRelay 1 1 n dev rfcomm1 If all goes well the Relay Q1 should become activated...

Page 14: ...he API mode has been started the MIAC will display its local IP address you should use to connect to the MIAC To communicate with the MIAC you will need to connect your controller PC Linux Phone Tablet etc to the WIFI network and then use the IP address provided by the MIAC Network Join Mode The join mode allows the MIAC to join an existing WIFI network The network to join and access password can ...

Page 15: ...le from the MIAC component menu to allow you to easily control the MIAC AllCode via the command API The component comes with a fully operational simulation allowing us to create and test programs before we move to the hardware The component s Mode property allows us to decide if we are using the component to control the simulation or the real hardware Bluetooth Serial Component Properties WIFI Com...

Page 16: ...s automatically opened when you start the simulation and closed when you end the simulation The console window shows the API commands as well as any return values allowing an easy way of seeing the communications between the simulation and the MIAC Downloading code to the MIAC Flowcode also allows us to create code which will run on the microcontroller on board the MIAC This is not recommended unl...

Page 17: ...apes with the same colour scheme can be joined together This technique encourages people of all ages to enjoy coding and develop their confidence and ability in computer programming Setting up App Inventor The key items you need are a desktop or laptop running a modern browser like Chrome or Firefox and a phone or tablet running the Android operating system You will also need a QR reader so it wou...

Page 18: ...ect as from the Projects menu and then entering an appropriate name for your project 3 Click Screen1 from the Components pane and set the AppName and Title in the Properties pane to something suitable 4 Drag a button from the User Interface panel onto the Viewer screen and alter its text to read Relay 1 On Also rename the button so it reads R1On Do the same again to create another button called Re...

Page 19: ...nventor website you will find instructions about other methods that are available for transferring your program to your Android device 8 You can now run your program on your Android device Click Connect to device and select the MIAC AllCode from the list Clicking the Relay 1 On button should make Relay Q1 switch on Clicking the Relay 1 Off button should make Relay Q1 switch off You may have notice...

Page 20: ...o communicate with the MIAC As will other languages you need to use the COM port number or IP address that the MIAC is connected to There are examples on the AllCode pages of the Matrix TSL website here https www matrixtsl com allcode resources Using C The program on the right shows a basic program in C You should use the namespace MIACAllCode and place the MA_DLL library file in the same folder a...

Page 21: ...ld be added to your project Remember also to put the MA DLL file into the same folder as your created EXE Using C The same program is shown on the right this time in C To use the DLL with C you need to reference the functions by including the MIAC_AllCode h header file You also need to add the MIAC_AllCode lib file to your Visual Studio project Also put the DLL into the same folder as the EXE you ...

Page 22: ...ww python org There are two versions of Python 2 and 3 and either can be used to control the MIAC AllCode but you may wish to ensure you have the latest version installed In addition to Python itself you will also need to install the PySerial library This can be found on GitHub https github com pyserial pyserial or can be downloaded on a Linuxbased device using the following command in a terminal ...

Page 23: ...e than one at the same time The program on the right shows how this can be done Just like the first program we start by importing the MA library note we are also importing the time library too We then create 2 instances of the API and open their COM ports The routine for drawing the square should be self explanatory Finally both COM ports are closed Theoretically many MIACs can be controlled simul...

Page 24: ...ite https www matrixtsl com allcode resources To begin create a new blank VI and then open the MIAC_AllCode lvlib file that was downloaded earlier This contains all of the function calls to the AllCode API as shown on the right A sample program is shown using eight switches to control the state of the Relay and Transistor outputs The program at the bottom of the page shows a flat sequence structur...

Page 25: ...s can be used with pulse width modulated PWM output and are numbered as follows Channel 0 Enable0 AB Channel 1 Transistor Output A Channel 2 Transistor Output B Channel 3 Transistor Output C Channel 4 Transistor Output D Channel 5 Enable1 CD Here is a block diagram of the internal workings of the transistor outputs The states of the control signals have the following effect on the transistor outpu...

Page 26: ...e of the input terminals Channel 1 to 8 Value 0 Input Low or 1 Input High Value ReadInputs Reads the binary values of all the input terminals Value 0 to 255 Value ReadAnalogInput Channel Returns the analog value of one of the input terminals Channel 1 to 8 Value 0 to 1023 Transistor Outputs Return Command Parameter s Description WriteTran Channel Value Writes a value to control a single transistor...

Page 27: ...ates X 0 to 119 Y 0 to 49 State 0 to 1 0 White 1 Black LCDBitmap X Y Filename Reads a monochrome or 24 bit colour bitmap file from the SD card and draws on the display X 0 to 119 Y 0 to 49 Filename filename bmp LCDOptions Foreground Background Transparent Sets the options for drawing to the LCD Foreground 0 to 1 Background 0 to 1 Transparent 0 to 1 LCDBacklight Brightness Controls the brightness o...

Page 28: ... file from the SD card Filename filename txt Status 0 to 255 0 OK 239 FileNotFound Real Time Clock Return Command Parameter s Description Value ReadRTC Unit Reads a value from the real time clock Unit 0 to 5 0 Sec 1 Min 2 Hour 3 Day 4 Month 5 Year Value 0 to 99 WriteRTC Unit Value Writes a value to the real time clock Unit 0 to 5 0 Sec 1 Min 2 Hour 3 Day 4 Month 5 Year Value 0 to 99 Serial Communi...

Page 29: ...Matrix Technology Solutions Ltd 33 Gibbet Street Halifax HX1 5BA t 44 0 1422 252380 e sales matrixtsl com www matrixtsl com CP8656 ...

Reviews: