Controlling transistors via usb

New to FreeBASIC? Post your questions here.
christuna
Posts: 4
Joined: Apr 03, 2021 7:02

Controlling transistors via usb

Postby christuna » Apr 04, 2021 0:19

Hi fellas.

I'm looking for a ready made device or a wiring diagram that would allow me to control around 10 transistors via usb port.

I'm sure that someone on here has built such a device.

Thanks in advance
MrSwiss
Posts: 3824
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Controlling transistors via usb

Postby MrSwiss » Apr 04, 2021 17:10

Hi,

I'm not certain that this is the right forum for you.
This is typically about software (that might control devices) but NOT about building those DIY style.
A forum specializing in DIY-hardware might be more appropriate for your aims.
grindstone
Posts: 797
Joined: May 05, 2015 5:35
Location: Germany

Re: Controlling transistors via usb

Postby grindstone » Apr 05, 2021 17:24

On the other hand: The capability of accessing USB by FB -analogue to GetMouse or GetJoystick would be a nice feature.
christuna
Posts: 4
Joined: Apr 03, 2021 7:02

Re: Controlling transistors via usb

Postby christuna » Apr 05, 2021 22:27

MrSwiss wrote:Hi,

I'm not certain that this is the right forum for you.
This is typically about software (that might control devices) but NOT about building those DIY style.
A forum specializing in DIY-hardware might be more appropriate for your aims.


Maybe I should have posted it under "Hardware Interfaces / Communication" section of the forum.

I posted it on this website since the two are very much connected - the software and the hardware.

grindstone wrote:On the other hand: The capability of accessing USB by FB -analogue to GetMouse or GetJoystick would be a nice feature.


You mean to say that there is no way for Freebasic to send commands through usb or maybe even receive them?
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Controlling transistors via usb

Postby badidea » Apr 05, 2021 23:25

christuna wrote:...
Maybe I should have posted it under "Hardware Interfaces / Communication" section of the forum.
I posted it on this website since the two are very much connected - the software and the hardware.

In that section, there is libpruio (BB D/A - I/O fast and easy) which might be useful for you. No experience with it myself.


christuna wrote:
grindstone wrote:On the other hand: The capability of accessing USB by FB -analogue to GetMouse or GetJoystick would be a nice feature.

You mean to say that there is no way for Freebasic to send commands through usb or maybe even receive them?

There is Libusb, but the problem is, how to talk to which USB device. Things are more complicated than 30 years where you could just set a few outputs pins on a printer port with 3 lines of code.
Maybe a virtual com-port device? With a simple serial protocol? Something like that must exist somewhere I would think.

(maybe an admin can merge the 2 topics, this and viewtopic.php?f=18&t=29303)
Last edited by badidea on Apr 07, 2021 23:02, edited 3 times in total.
bfuller
Posts: 351
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Re: Controlling transistors via usb

Postby bfuller » Apr 06, 2021 2:40

The easiest way to do what you want is to connect an Arduino to your USB port and send serial commands to it from FreeBasic.
Have a simple serial receive sketch in your arduino to interpret the serial command and set the GPIO output accordingly.

You can also send GPIO input back to the PC using the serial port, or even use A/D converter to read analog voltages.

Yes, the Hardware area of this forum is the proper place-----and if you look in there you will probably see examples where others have already done it.

The Arduino IDE comes with multiple example sketches to do exactly what you want.
Dinosaur
Posts: 1368
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: Controlling transistors via usb

Postby Dinosaur » Apr 07, 2021 21:23

Hi All

It also depends on why you mention Transistor.
If you are using the transistor to turn on a more powerful device like a relay, then there are may options.
Just browse for usb relay. Many cheap boards out there.

On the other hand I find using Wifi so much simpler, again browse for Wifi Relay.

Regards
TJF
Posts: 3620
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Controlling transistors via usb

Postby TJF » Apr 07, 2021 22:24

badidea wrote:In that section, there is libpruio (BB D/A - I/O fast and easy) which might be useful for you. No experience with it myself.
No USB feature in libpruio, but very fast direct hardware access.

Note:
libpruio is a hardware driver for the Texas Instruments AM335x SoC (CPU), working best on BeagleBoard computers (but not on PCs).
AWPStar
Posts: 42
Joined: May 03, 2009 21:47

Re: Controlling transistors via usb

Postby AWPStar » Apr 11, 2021 22:03

You can try Arduino, Or any other microcontroller(like attiny 85) that can emulate usb device.
caseih
Posts: 1697
Joined: Feb 26, 2007 5:32

Re: Controlling transistors via usb

Postby caseih » Apr 11, 2021 22:41

The easiest and most common way of using an Arduino for this purpose is to control the Arduino via serial commands. Plug in the arduino with usb, it shows up as a serial port. Write a program for the arduino to interpret simple commands and control some hardware. Then FB just has to open the serial port and read and write from it.

There is even a standardized protocol and firmware for Arduino to do this sort of thing called Firmata. It could be overkill for what you are doing, but it's widely used. There's a C client library that could be used from FB: https://github.com/grandsmarquis/FirmataC
Dinosaur
Posts: 1368
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: Controlling transistors via usb

Postby Dinosaur » Apr 11, 2021 22:55

Hi All
You mean to say that there is no way for Freebasic to send commands through usb or maybe even receive them?
Top
You can use Libusb which I have used in Linux So if you are not into Arduino /rPi or Beaglebone but instead want to
just use your PC or Laptop then that may be the way.
The listing below (without the actual code) describes what needs doing to communicate with a usb device.

Code: Select all

''This program does the following:
''  0: Do some Main Thread stuff before creating usbThread.
''  In the usbThread does the following.
''  ------------------------------------
''  1: Initialize: Libusb,
''  2: Gets List of usb devices attached.
''  3: Uses 0-7 idVendor/idProduct's to find matches in list in usbIO.bi
''  4: Opens matches found and assign's .Handle(n).
''  5: Uses .Handle(n) to check if Kernel has control, then releases it.
''  6: Uses .Handle(n) to Claim Interface & load ascii string desc to get iSerialNumber.
''  7: Uses usbAccesInit to send init cmnds to possible AccesIO devices.
''  8: Now .Handle(n) is available to Write & Read Control Transfers to devices attached.
''  9: usbThread checks flags to confirm all OK, then sits in loop until Quit.
'' 10: WriteOntrak & ReadOnTrak are dedicated to Ontrak ADU70 Load Cell's.
''     Read & WriteAcces are dedicated to AccesIO USB-IDIO-16L. and USB-AO16-4E
'' 11: Quit Deallocates Buffer, and closes Interface's and Libusb.
''---------------------------------------------------------------------------------------
If you are interested I can list the actual code I used for specific devices.
Regards

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests