Programming Hardware

BlitzMax Forums/BlitzMax Programming/Programming Hardware

BLaBZ(Posted 2010) [#1]
This is something I've been curious about for awhile....

I've always wanted to know how to program hardware, for example, my friends into robotics, and I was wondering if there was a way to write software to control the motors?

Yesterday I was asked if I could right code to detect when a sensor was set off,

What type of programming is this? How would I go about writing software like this?

I've googled this without much luck,

thanks guys!


Yeshu777(Posted 2010) [#2]
Yes, it's embedded programming.

Have a look a Microchip PIC website - stepper motor control etc.

Atmel also do the AVR range.

I tend to do this as a day job - albeit on a larger scale, so feel free to email me if you want further advice.

Best Regards,


zambani(Posted 2010) [#3]
There are 2 ways to go about. One way is what Yeshu777 described. You program a microcontroller via a serial interface from your host computer. The upside to this method is once the microcontroller is programmed, you can disconnect from the host and it will still work. The downside is that you're more or less limited by the capability of the microcontroller.

The other way is to use a USB I/O board. While some of these boards in fact also have microcontrollers built into them, all of the programming can be done in your preferred language via the supplied dll's. The downside however is that the host must always be connected to the board since it's the one actually running the program.
There could also be speed issues depending on how the host communicates the IO's.

For what I do(lab experiments), I prefer the second method since mobility is not an issue. This way I can program everything in Biltzmax. My setup also runs on a netbook so in kinda mobile to.


Czar Flavius(Posted 2010) [#4]
http://en.wikipedia.org/wiki/AIBO
You can reprogram these, via wireless network connection or memory stick. Could be a fun (if expensive) way to experiment.


Charrua(Posted 2010) [#5]
hi
on XP and if you have a paralell port (the old printer port) and with DLPORTIO.dll (google to find it) you could do in and out to that port, this were one of my trials some time ago:

Rem

	My "Hellow World" in BlitzMax!

		A simple application that sends 1000 count values a second to the base port
	of LPT and read 4 times a second the status port (base+1)
	
	Just for test DLPORTIO.dll, thank´s Nigel Brown for your help!

End Rem

Strict

Graphics 640,480,0


Global	DllHandle=LoadLibraryA("DLPORTIO.dll")
Global	DlPortReadPortUchar:Byte( port:Int )"Win32"=GetProcAddress(DllHandle,"DlPortReadPortUchar")
Global	DlPortWritePortUchar( port:Int, value:Byte )"Win32"=GetProcAddress(DllHandle,"DlPortWritePortUchar")

Global Pasada
Global Vueltas
Global Lectura


Const PuertoDatos   = $378	'base LPT adress in my machine, 8 bits (output)
Const PuertoEstado  = $379	'status port 5 most significant bits used (input)
Const PuertoControl = $37A	'4 bits (thre of them inverted) bit 5 stablish the 
							'direction of data port, by default bit cleared
							'data port is output.

Delay 10

Pasada = 0
Vueltas = 0

While Not KeyHit(KEY_ESCAPE)
	
	DlPortWritePortUchar(PuertoDatos,Pasada)		'write nex value to the port
	Pasada = Pasada + 1
	Delay 1
	'1 ms BitTime in Bit0 of LPT data port = 500 Hz square signal (pin 2 of the DB25 male connector)
	'2 ms BitTime in Bit1 of LPT data port = 250 Hz square signal (pin 3)
	'and so on... in powers of 2
	'128 ms BitTime in Bit7 of LPT data port (pin 9)


	If Pasada=250 Then
		Pasada=0
		Vueltas=Vueltas+1
		'read status pins four times a second
		Lectura = DlPortReadPortUchar(PuertoEstado) ~ $80	'msb is inverted
		Cls
		DrawText "Vueltas: "+Vueltas,20,20
		DrawText "Lectura: "+Right(Bin(Lectura),8),20,40	'show just 8 bits
		DrawText "Lectura: "+Lectura,20,60
		Flip
	End If
Wend

DlPortWritePortUchar(PuertoDatos,0)

End


and of course you can program some external microprocessor hardware but i think that for a spepper motor is better wiht the paralell port (and is cheaper, if you still have an old pc with it), there are lot of paralell port programming examples

do a google searcha for: "stepper motor paralell port" or something similar.

probably you have to have some electronic skills, if don`t, ask again, i'll try to help.

Juan


BlitzSupport(Posted 2010) [#6]
Have a look at Arduino -- this is something I intend to play with eventually. The boards are very cheap indeed and look really easy to program using the supplied IDE.