Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:50 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Raspberry Pi CP2102 programming ......

Author Message
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 01:08am 19 Jul 2022
Copy link to clipboard 
Print this post

I have one of these .....
It works with a Pico with the UART set to MIDI baudrate
and running the script.
I would like to go directly from USB to the synth board.
I now have this ....
I think it will convert USB to MIDI , but haven't a clue
how to program it ????
The code below shows a datastream ( strangely ? ) off
the TX pin.  


import serial

#Serial takes two parameters: serial device and baudrate
ser = serial.Serial('/dev/ttyUSB0', 9600)

while True:
   ser.write(bytes([144,60,127]))

my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 06:04am 19 Jul 2022
Copy link to clipboard 
Print this post

The CP2102 is a USB to serial bridge. Windows sees it as a USB device and creates a COM port for it. It doesn't require programming, that's done by changing baud rate etc. on the virtual COM port that windows creates when it sees the CP2102. The baud rate for the CP2102 is set by changing the settings of the virtual COM port.

The serial I/O connections on the CP2102 are at 3.3V logic levels and I suspect would need some conversion to connect to MIDI, which IIRC uses opto couplers and 5V supplies.

After that you are on your own. I've no idea about the DreamBlaster.  :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5090
Posted: 01:59pm 19 Jul 2022
Copy link to clipboard 
Print this post

Hi Hitsware,

I assume you are trying to send MIDI (serial) to the module (and not parallel).
The CP2102 communicates USB to a PC, where you can use a terminal program or you can use MMB4W or MMB4DOS or MMB4L to send data to it. Although the connection between the PC and the CP2102 is USB, and can use various speeds, the serial connection (UART) needs to have the correct baudrate before the MIDI module will understand.

If you look at wikipedia, you can see that the serial baudrate for MIDI must be 31.25kbps. If you can set this exact baudrate in your program (Maybe the CP2102 does not support this baudrate) you should be able to send commands to the module.

Connect ground to ground, and the CP2102 TX PIN TO  SAM2695 (the chip) pin 16. Not sure what the module pin is.

When (after careful trying) it does not work, maybe you need to invert the TX signal (the MIDI circuit is not shown in the board documentation, so I am not sure you need an inverter or not).

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 05:47pm 19 Jul 2022
Copy link to clipboard 
Print this post

  Volhout said   Although the connection between the PC and the CP2102 is USB, and can use various speeds, the serial connection (UART) needs to have the correct baudrate before the MIDI module will understand.


Right .... This works with module connected to Pico :


from machine import UART, Pin
fo = UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5))

fo.write(bytes([192,26,193,13,194,107,195,115]))

my site
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 05:53pm 19 Jul 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  I've no idea about the DreamBlaster.  :)


Click here for next best thing to the DreamBlaster......
my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 06:26pm 19 Jul 2022
Copy link to clipboard 
Print this post

You need a terminal or something that will let you send bytes from the PC. Wouldn't MMB4W work doing that now?

If you use Tera Term, you can see the new com port that windows makes when you connect the CP2102. Type the 31250 baud rate into Tera Term (it doesn't show it on the list as it only shows standard baud rates).

Then send the ASCII characters for those decimal values. Sorry, I don't know how to do that in Tera Term unless you can type them on the keyboard. No spaces.

You may have to experiment with Tera Term to find out if you need CR, LF or both.

Pretty board, but as soon as I read "Arduino" I lost interest. lol
Edited 2022-07-20 04:32 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 07:23pm 19 Jul 2022
Copy link to clipboard 
Print this post

       

........I T   W O R K S !!!!!!! .....

######## Ten Notes From Heaven ########
import time
import serial
ser = serial.Serial('/dev/ttyUSB0', 31250)  
#print(ser.name)
for i in range(10):
   ser.write(bytes([144,60,127]))
   time.sleep(0.5)
   ser.write(bytes([144,60,0]))
   time.sleep(0.5)
ser.close()

I didn't think the RPi would produce
the right baud , but it does !
my site
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5090
Posted: 02:58am 20 Jul 2022
Copy link to clipboard 
Print this post

Again, it is not the rpi, but the cp2102 that creates the baudrate..
PicomiteVGA PETSCII ROBOTS
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 05:01pm 20 Jul 2022
Copy link to clipboard 
Print this post

  Volhout said  Again, it is not the rpi, but the cp2102 that creates the baudrate..

Unlike RS232 ?
my site
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 05:27pm 20 Jul 2022
Copy link to clipboard 
Print this post

  hitsware2 said  
  Volhout said  Again, it is not the rpi, but the cp2102 that creates the baudrate..

Unlike RS232 ?

What?!

Something along the lines of RS232 is happening but at that specific baud rate - which is being handled by the cp2102.  The CPU, be it RPi or not, is using USB.  Setting the baud rate involves the host (RPi/etc) telling the cp2102 what rate to use.

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 05:51pm 20 Jul 2022
Copy link to clipboard 
Print this post

The CP2102 includes a set of registers, a programmable baud rate generator and a UART. It transfers data over its TX and RX pins at the speed set by the baud rate generator. The host device writes to the registers on the CP2102 to define communication parameters such as baud rate.

The USB link runs independently to the CP2102 TX and RX pins. It can transfer data much faster than the baud rate generator can clock the UART.

RS-232 is a hardware definition for communication signals. The baud rate used isn't part of the RS-232 standard.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:25pm 20 Jul 2022
Copy link to clipboard 
Print this post

Some (most), but not  all USB-TTL adapters can set their baud rate to any value. Others are restricted to the 'standard' values.
For some, it depends on the operating system and the drivers.

Your choice of CP2102 was fortunate.

Jim
VK7JH
MMedit
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 02:15am 21 Jul 2022
Copy link to clipboard 
Print this post

  TassyJim said  Your choice of CP2102 was fortunate.


A shame to only use 3 pins .


my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 06:31am 21 Jul 2022
Copy link to clipboard 
Print this post

The CP2102 is a pretty old chip now and there are nicer alternatives. Some of the cheap boards that use it seem to be using some rather dodgy clone chips that have some very poor characteristics.

Be careful with VDDout. It comes from a tiny voltage regulator and is ok for pull-up resistors but not that much more.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 02:48pm 21 Jul 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  Be careful with VDDout.

I'm using VBUS to power the synth and that
works ( possibly some noise )
Maybe I should try VDD ?
my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 04:34pm 21 Jul 2022
Copy link to clipboard 
Print this post

VBUS is 5V from the USB. VDD out is supposed to be 3.3V, but sometimes it isn't! There have been cases of it being at 5V. The *total* current output from the regulator is supposed to be 100mA, in theory you have about 90mA available at 3.3V. Don't take this as gospel without testing it (gently) on dummy loads first as the Chinese take a remarkably flexible view of specifications. You may need to put decoupling caps from VDD to GND at the module.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 05:55pm 25 Jul 2022
Copy link to clipboard 
Print this post


import serial
fo = serial.Serial('/dev/ttyUSB0', 31250)

while True:
   fo.write(bytes([255]))

Tried a new chip and it appeared to
be working , but no music .
Above test measures 3.12 kHz on working
unit , but 3.85 kHz ( nearest standard ? )
on non working unit .....
my site
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025