and DMX512 Using Flowcode

By Ben Rowland, This article will investigate some of the more complex communications Embedded Engineer components, Modbus and DMX. Both of these components basically let you do the same thing, which is to use one device (Master) to control one or more remote devices (Slaves).

Flowcode is a programming tool for means, so you can control the real-world microcontrollers. It uses simple flowchart electronics from your PC. icons which can be built up to create simple through to complex programs. Flowcharts DMX 512 can be organized into macros and macros DMX512 may be familiar to DJs, stage can be packaged up into components lighting technicians and model railway allowing for a very flexible and modular enthusiasts, where it has a number of approach to programming. Each packaged common applications. Communication is component features a full simulation one-way, so it is used to send data from allowing you to test your design in software the master to the slave—no data can be before going near any hardware. It will also sent back the other way. Also, DMX512 let you interact with hardware via various only allows 8-bit bytes to be transferred

Matrix TSL’s Flowcode software allows you to quickly and easily develop complex electronic and electromechanical systems. Engineers use Flowcode to develop systems for control and measurement based on microcontrollers, on rugged industrial interfaces or on Windows compatible personal computers. Flowcode 7 feaures a stylish and modern new UI that gives users an easy-to-use, advanced graphical programming Download a Free Trial IDE for their microcontroller project requirements. and/or Buy Flowcode 7 flowcode.co.uk/circuitcellar/

If you purchase a product or service via Flowcode.co.uk/circuitcellar, Circuit Cellar will receive an affiliate commission. Circuit Cellar only promotes those products or services that it feels will deliver value to you. SPONSORED CONTENT Figure 1 - DMX512 Slave channels set using Flowcode so single bits of data have to be packed MODBUS together inside a byte, or multiple bytes Modbus is used heavily in industry, from must be used to transfer values larger the control of motors and actuators to than 255. sampling sensors and returning results. Each DMX slave device can either have For example, a robot arm in a factory may a unique address or can use different have a Modbus slave device controlling sections of the same message. For the various moving parts of the arm example, the master sends a DMX data and collecting data from sensors (e.g., chain of 24 bytes using the address byte ultrasonic proximity sensors or tactile 0x20. Two slave devices have the address press switches. 0x20, the first slave uses data channels Modbus has four types of data that can be 0-11 and the second slave uses data transferred between the master and slave: channels 12-23 (Figure 1). The DMX512 example programs allow • Digital States (Coils) – Master <-> the master to control two slave devices. Slave – 1-bit values The master uses two full 8-bit ports • Digital Inputs – Master <- Slave – 1-bit to read the value of slide switches. values The switches connected to PORTB are • Analog Values (Register) – Master <-> sent to slave node 1 and the switches Slave – 16-bit values connected to PORTD are sent to slave • Analog Inputs – Master <- Slave – 16- node 2 (Figure 2). bit values

Figure 2 - E-blocks DMX512 1 Master and 2 Slaves

SPONSORED CONTENT Figure 3 - Specifying Modbus device addresses using Flowcode

The slave device stores the various the master to collect. This time the values so the number of unique addresses Modbus devices are connected together is set in the Modbus slave component using RS-485 to allow the data direction properties (Figure 3). Each Modbus slave to be controlled and allow bi-directional device has its own address which can be communications (Figure 4). specified as a single byte (255 available devices) or as two bytes (65535 available FLOWCODE INJECTORS devices). Address 0 is reserved for The Flowcode injector components broadcast to all type messages. enable the connection of communications The Modbus example programs allow components to actual external devices the master to read sensor values back inside the Flowcode simulation. In the from two slave nodes. The master examples the vNet injector is used, which reads the analog input register for slave allows two or more instances of Flowcode addresses 1 and 2. The slaves constantly simulation to communicate together. If sample their sensor and update the the COM port injector was used instead, value in the correct register ready for the simulation could talk to real-world

Figure 4 - E-blocks Modbus 1 Master and 2 Slaves

If you purchase a product or service via Flowcode.co.uk/circuitcellar, Circuit Cellar will receive an affiliate commission. Circuit Cellar only promotes those products or services that it feels will deliver value to you. SPONSORED CONTENT hardware via a PC COM port. To set up 485 compatible voltages. If the device is the vNet component to communicate, bi-directional as is the case with Modbus, you need to first check that the network then an extra microcontroller pin is interface is the same for both components: required to control the data direction of a correct setting should display your the MAX3078 IC. The Modbus component computer’s IP address, which will be used has an RS-485 mode which will do all the to route the communications. The TCP manipulation of the data direction pin for channel should be unique to the Flowcode you. instance and can range from 0-7. The Master component outputs data on port CONCLUSION 4001 and listens for incoming data on port Connecting systems together using 4000. The Slave components outputs data communications busses is often seen as on port 4000 and listens to port 4001. a hard undertaking which can lead many engineers to struggle. Flowcode not MULTIPLE SLAVES only simplifies the process of connecting When dealing with a single slave device, systems together, but also allows devices you can simply connect the transmit pin of to be created using existing standards. the Master to the receive pin of the Slave Adopting an existing communications and vice versa. If you need the distance standard means your product can be between microcontrollers to be significant compatible with a wide range of off the (more than a meter or two), then you shelf products as well as a great number could use a driver chip such as a MAX2323 of end users who may be already familiar to convert the TTL signals up to RS-232 with the . compatible voltages. When using multiple slaves, the connections become a bit more difficult as Ben Rowland is a graduate of the University of Huddersfield in the UK, you need a way to connect all the slave where he earned a Master’s degree in Embedded Systems & Cybernetics transmit pins to the master receive pin, before going on to work in the Flowcode development team at Matrix TSL without conflicting with one another. where he has worked for more than 10 years. One way is to use a driver chip such as a MAX3078 to convert the signals to RS- FREE

Flowcode is an IDE for electronic and electromechanical system development. Pro engineers and academics can use Flowcode to develop systems for control and measurement based on microcontrollers or on rugged industrial interfaces using Windows-compatible personal computers. Visit www.flowcode.co.uk/circuitcellar to learn about Flowcode 7. You can access a free version, or you can purchase advanced features and professional Flowcode licenses through the modular licensing system. If you make a purchase through that page, Circuit Cellar will receive a commission.

Download a Free Trial and/or Buy Flowcode 7 flowcode.co.uk/circuitcellar/

SPONSORED CONTENT