[PYTHON] Automatic hardware design tool for web programmers mille-feuille-program edition

From trial production using a mille-feuille board to mass production in small lots, the same program can be run as it is by simply replacing the automatically generated wiring information file. I will explain how to actually write a program on the Millefeuille board.

How to write a program

How do you write the program after assembling the millefeuille? I will explain using the simplest AD2ch device board.

AD2chTest.py


#!/usr/bin/python

from mil import mil
from mil import milMod
from mil import p

from mil import AD2ch

import time

if __name__=='__main__':
	try:
		mil.init()
		modA = milMod.milMod(AD2ch.getInfo(0))	#connector number 0

		while(1):
			modA.connect()
			returnData = AD2ch.read(modA,0)
			print "AD 0ch = ",returnData
			returnData = AD2ch.read(modA,1)
			print "AD 1ch = ",returnData
			modA.disconnect()
			time.sleep(1)

	except KeyboardInterrupt:
		print("detect key interrupt [ctrl]+ [C] \n")

	mil.cleanup()
	AD2ch.cleanup()

1. First of all, routine work

First, import the required libraries. The library will be published later.

python


from mil import mil
from mil import milMod
from mil import p

Import libraries for each device

python


from mil import AD2ch

Others, import if necessary

python


import time

define main

python


if __name__=='__main__':

try-except puts the processing when exception handling occurs. Specifically, I / O status is cleaned up after the program is forcibly stopped with ctrl + c. It is recommended to clean up.

python


try:
...
except KeyboardInterrupt:

2, initialization and instantiation

Basically set I / O at initialization.

python


mil.init()

Instance generation

python


modA = milMod.milMod(AD2ch.getInfo(0))

AD2ch device information (device address, device board wiring information, etc.) is associated with this instance. The instance name is arbitrary. There are four connectors on the Millefeuille baseboard. Please specify which connector in it you connected to. You can connect up to four device boards of the same type. For I2C devices only, the I2C address is determined by the manufacturer, so some device boards can only use one.

HardAll.jpg

3, automatic wiring and device board operation

Wires the device board automatically. Usually, the work of wiring by hand is automated.

python


modA.connect()

When disconnecting

python


modA.disconnect()

By including the instance in the argument and passing it to the function of the library, the wiring information is grasped and it is automatically determined which I / O should be moved to move the device board.

python


returnData = AD2ch.read(modA,0)

Here, the data of the 0th channel of AD is acquired.

4, Firmware after automatic circuit diagram generation

After writing the program and completing the trial production, let's generate the schematic. See the previous article for how to generate it. http://qiita.com/my_mil_info/items/ac484c96c867c1b3e702

When the circuit diagram is automatically generated, the firmware is also automatically generated according to the circuit diagram. This firmware is "Wiring data (wiringdata.py)" and is a file related to wiring that is referred to when creating an instance. If you replace this with the automatically generated firmware of the same name (wiringdata.py), you can use the program prototyped using Millefeuille as it is in the automatically generated circuit.

Recommended Posts

Automatic hardware design tool for web programmers mille-feuille-program edition
Automatic hardware design tool for Web programmers mille-feuille-Hardware mechanism
Automatic hardware design tool for Web programmers mille-feuille-What is an automatic circuit diagram generation tool?
Hardware for web programmers mille-feuille Support tool for Raspberry Pi
[Python] Web application design for machine learning