309

A much simpler way than the the Raspi's Pin Header for connection is USB. Connect an Atmel AVR-USB Controller with your Raspi. This is simplified by the small USB library in bascom, c and assembler for AVR-USB-controller!You had 4 excuses for not using USB in your project!1. Too complicated!Not true if you use this small library.

A much simpler way than the the Raspi's Pin Header for connection is USB. Connect an Atmel AVR-USB Controller with your Raspi. This is simplified by the small USB library in bascom, c and assembler for AVR-USB-controller!

You had 4 excuses for not using USB in your project!

1. Too complicated!

Not true if you use this small library.

2. Atmel AVR-USB Controller are not available in DIP form.

Using a cheap breakout-board like Teensy, U4DIL or Leonardo has many advantages. The crystal , reset circuit and USB connector are already soldered. USB is powering your project with 5V and no programmer is needed (bootloader).

3. Windows needs special driver.

Not if you use the HID-Version of the library.

4. I need to program complicated software on the PC side.

Python with pyusb is the solution. With 6 lines of code you can get or send your data! In addition software in C/C++ with Qt is available.

 

The library uses interrupt routines. After including the library and the call of a subroutine (USBINI) in your program you need only 3 variables for accessing the data: A Counter for the number of Bytes, a buffer of 64 Byte for the data and a Flag to signalize data is ready or to poll if data is available. Here an example for sending 2 Bytes in Bascom:

Ep1_cnt = 2 'send 2 Bytes

Disable Interrupts

Ep1_buf(1) = 20 '1 Byte = 20

Ep1_buf(2) = 10 '2 Byte = 10

Enable Interrupts

Ep1_flag = 1 'data is ready

 

And here the Python Code for reading 2 Bytes from the Raspi (or PC):

 

Vendor_ID = 0x3EB #(ATMEL)

Product_ID = 0x02 #usb_small_lib "hid"

import usb.core, time

dev = usb.core.find(idVendor = Vendor_ID,idProduct = Product_ID)

dev.set_configuration()

res = dev.read(0x81, 2) # read 2 Byte (ADC) from endpoint1 (0x81)

 

 

More information on www.weigu.lu/b/usb. Momentary only a German description is available.

Although in German a wast assembler tutorial on www.weigu.lu/a.

 

Happy coding!

weigu