Hi all,
I know almost everything is backorder these days but might as well ask
I am wondering if anyone had already built PCBs with USB functionality?
I never built a usb interface myself, but I would like to do it and start off with a simple USB game controller. something simple: buttons --> atmega328p --> usb-bridge --> PC
I inherited from a full spool of smd Atmega328p's so I want to do all of my projects with this chip. The Atmega32u4 are expensive and too anyway...
So, I am looking for a cheap and easy to use chip that could be used as a usb bridge?
I have a atmel ICE, and I use platformIO, so ideally something that could be programmed with these tools would be great. SMD too preferably.
CH340 is usually the cheapest to get, especially if you import directly from China. There are many versions of this chip; one of the notable differences is that some require an external 12MHz ceystal while others don't. This can obvipusly impact total costs and pcb size. They also come in different footprints.
I've used CH340G mostly with an external 12MHz crystal; works fine if you follow the (scarce) pointers in the datasheet.
CP2102 (and family members) is popular as well, but more costly and not necessarily better IME.
I've done several designs using Microchip's MCP2221. It's very easy to use and requires no drivers for I2C communication and configuration on the PC since it's a HID device.
CDC driver is available and automatically installed for Windows. Mainline support in Linux.
Thank you! I tried working with V-USB in the past few days, but I could not achieve anything.
I followed this tutorial for the hardware AVR ATtiny USB Tutorial Part 1 | Code and Life and for setting up the vusb folder and usbconfig file. To my understanding, for a HID device, I do not need to setup a CLI software on the host side, I should only need the firmware on the atmega328p and this should be enough to operate as a keyboard?
However, I did not want to mess with makefiles and c programming so I basically just dumped the v-usb library in a platformIO Arduino project and added it to the library paths.
I did have to change main() for setup() and loop() however. and I also changed void pointer castings into struct castings
usbRequest_t *rq = (void*)data;
into
usbRequest_t *rq = (usbRequest_t *)data;
Since the former would cause an error in C++.
Now, everything compiles and the hardware isn't different. But it doesn't work, I get usb error 43 when I plug the usb jack in the PC.
I wonder if the whole attempt of using platformIO with Arduino core is what causes issues, or maybe its the way I typecast the usbRequest_t struct that creates padding errors, or maybe my understanding of HID devices is wrong and I need to install drivers or to run some kind of software on the host side?
I did a test last week with a V-USB analog logger from 10 years back! On my Surface Pro 4 Win 11 machine, there was no issue. Who knows about other machines, but as long as the USB controller conforms to USB 1.1 specs (old keyboard or very old mouse could be a compatibility test) things should work, IMO. The real issue with V-USB is that the zener diodes are very critical, I ordered quality Vishay part.
I would recommend going back to a 2012 Arduino IDE version.
Sometimes I forget that the Adafruit Trinket/TrinketPro is essentially V-USB (while Frank Zhao worked for Adafruit; Frank designed the USBSnoobie board.) So much for the history lesson.
I pulled up a Atmega328P sketch for a trinketPro and it compiles under IDE 1.8.18 on Win-11 with no errors.
The Zip and required library are attached for anyone wishing to take a trip back in time (TrinketPro OR homebrew USB-V req.)
// *******************************
// HID Serial Example
// Print analog sensor values
// RAYSHOBBY.net
//
// This program opens an HID serial channel and shows how to send and receive messages from a host
// computer. To use it, you need to run the HIDSerialMonitor from a host computer. The program
// repeatedly prints out the value on a specific analog pin. Typing 'a?' (where ? is a number between
// 0 to 5) in the serial monitor changes the selected pin.
// *******************************
#include <HIDSerial.h>
#include <Streaming.h>
HIDSerial serial;
unsigned long t = 0;
unsigned char buffer[32];
unsigned char adcCh = 0;
void setup() {
serial.begin();
serial << "HID Serial For Trinket" << endl;
}
void loop() {
int value;
if (millis() > t + 2000)
{
t = millis();
serial << "A" << adcCh << " = " << analogRead(adcCh) << endl;
// serial.write('A');
// serial.print(adcCh);
// serial.print(" = ");
// serial.println(analogRead(adcCh));
}
if(serial.available()) {
int size = serial.read(buffer);
if (size!=0) {
//serial.write((const uint8_t*)buffer, size);
if(buffer[0]=='a' || buffer[0]=='A') {
if(buffer[1]>='0'&&buffer[1]<='5') {
adcCh = buffer[1]-'0';
serial.write('A');
serial.print(adcCh);
serial.println(" selected.");
}
}
}
}
serial.poll();
}
Fully USB 1.1 compliant low-speed device, except handling of communication errors and electrical specifications.
But, I concede that I have only experimental experience and that was mostly 10 years ago; however, every one of my many designed worked (at least one still does under Linux Mint and Windows 11 on HP Elitebook and Microsoft Surface.)
I have (personally) never considered it prime-time commercial technology but apparently the folks at Objective Development think so (or did) as commercial licenses are (were) available.
So apart from the IDE, is there anything wrong with my approach? Its just that I feel like Im working with a black box and I find it hard to determine where to start debugging. It doesn't work and I cant tell what is wrong. Ill check on the scope to see if st least something comes out of the data lines, but otherwise, the data could be jibberish and I wouldn't know.
I didnt mention, The tutorial used a 3v3 reg, so that is what I am using. This voltage is out of spec for the 16mhz crystal i am using, but I read it was mostly reliable and I tested with other programs. But it may not work with usb, timing may be more critical. I will try at 5v with the zeners
The signal is literally 0v flat when I power on with the scope. (I just plugged the scope on the USB D+)
I also wasn't able to test the zener circuit, I do not have any zener with zener voltage under 4v...
But I was thinking I could try the RT232, I have a TTL to USB in my possession. But I have a hard time understanding how I could use these chips to create a keyboard or game ctrler... If I check the device class, its undefined (0xFF)
With a USB to serial converter you would need some software running on the host that converts serial commands to keystrokes (or whatever you're gonna need). I personally wouldn't bother with v-usb, either get a microcontroller with a USB peripheral or stick to the serial based approach.