Code Monkey home page Code Monkey logo

ch376msc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ch376msc's Issues

programatical filename for write to, results in unreadable file

  // Custom filenames causes issues opening file
  //String fileName = filename.substring(0, 8);
  //fileName = fileName += ".EXT";
  //flashDrive.setFileName(fileName.c_str());  // does not work 
  flashDrive.setFileName("TEST.TXT");   // works

Works fine!
flashDrive.setFileName("TEST.TXT");

but if I try setting the filename dynamically:

  //String fileName = filename.substring(0, 8);
  //fileName = fileName += ".GCO";
  //flashDrive.setFileName(fileName.c_str());  // does not work 

File gets created, but cannot open it in Windows: opening the file from explorer:

image

writefile(string)

I am trying to use the USB as a csv data logger and I am not sure if I am off, but char writing seems a bit cumbersome, vs #variables particular with #number values such as int.

is it possible to directly write an integer?

The ch376msc guide states:
flashDrive.writefile(string, strlen(string)); //string, string length
//but string really this is really a char string

for data logging it is fairly straight forward to add int, floats, etc.

//standard sdFat.h then example is
file.print(float); file.println();

//CH376msc.h requires example
string.toCharArray(charstring,10)
//then
writefile(charstring, strlen(charstring));
`
this all gets quite cumbersome when dealing with multiple data variables including floating points.

writeFile buffer too small?

I am trying to upload a text file to the USB drive:

  1. ESPAsync handler:
void handleUsbUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
  if(!index){
    Serial.printf("UploadStart: %s\n", filename.c_str());
    // Custom filenames causes issues opening file
    //String fileName = filename.substring(0, 8);
    //fileName = fileName += ".EXT";
    //flashDrive.setFileName(__dataFileName);
    flashDrive.setFileName("TEST.TXT");
    flashDrive.openFile();
    uploadedBytes = 0;
  }
   
  flashDrive.writeFile((char*)data, len);
  uploadedBytes = uploadedBytes+len;
  Serial.print("Recv: ");
  Serial.print(len);
  Serial.print(" in chunk, total bytes recv: ");
  Serial.println(uploadedBytes);
          
  if(final){
    delay(1000);
    flashDrive.closeFile(); 
    uploadedBytes = 0;
    Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index+len);
  }
}

This does succesfully create the file, but I am missing about 90% of the text data in the resultant file.

Logging out the sizes:

It seems that espasync webserver delivers the uint8_t data as the size of the MTU (1436 it seems)
So is there some limit to the size of buffer that flashDrive.writeFile() can handle (thus dropping the rest of the data?)
How can i go about writing the big buffer reliably

UploadStart: file.txt
Recv: 1271 in chunk, total bytes recv: 1271
Recv: 1436 in chunk, total bytes recv: 2707
Recv: 1436 in chunk, total bytes recv: 4143
Recv: 1436 in chunk, total bytes recv: 5579
Recv: 1436 in chunk, total bytes recv: 7015
Recv: 1436 in chunk, total bytes recv: 8451
Recv: 1436 in chunk, total bytes recv: 9887
Recv: 1436 in chunk, total bytes recv: 11323
Recv: 1436 in chunk, total bytes recv: 12759
Recv: 1436 in chunk, total bytes recv: 14195
Recv: 1436 in chunk, total bytes recv: 15631
Recv: 1436 in chunk, total bytes recv: 17067
Recv: 1436 in chunk, total bytes recv: 18503
Recv: 1436 in chunk, total bytes recv: 19939
Recv: 1436 in chunk, total bytes recv: 21375
Recv: 1436 in chunk, total bytes recv: 22811
Recv: 1436 in chunk, total bytes recv: 24247
Recv: 1436 in chunk, total bytes recv: 25683
Recv: 1436 in chunk, total bytes recv: 27119
Recv: 1436 in chunk, total bytes recv: 28555
Recv: 1436 in chunk, total bytes recv: 29991
Recv: 1436 in chunk, total bytes recv: 31427
Recv: 1436 in chunk, total bytes recv: 32863
Recv: 1436 in chunk, total bytes recv: 34299
Recv: 1436 in chunk, total bytes recv: 35735
Recv: 1436 in chunk, total bytes recv: 37171
Recv: 1436 in chunk, total bytes recv: 38607
Recv: 1436 in chunk, total bytes recv: 40043
Recv: 1436 in chunk, total bytes recv: 41479
Recv: 1436 in chunk, total bytes recv: 42915
Recv: 1436 in chunk, total bytes recv: 44351
Recv: 1436 in chunk, total bytes recv: 45787
Recv: 1436 in chunk, total bytes recv: 47223
Recv: 1436 in chunk, total bytes recv: 48659
Recv: 1436 in chunk, total bytes recv: 50095
Recv: 1436 in chunk, total bytes recv: 51531
Recv: 1436 in chunk, total bytes recv: 52967
Recv: 1436 in chunk, total bytes recv: 54403
Recv: 1436 in chunk, total bytes recv: 55839
Recv: 1436 in chunk, total bytes recv: 57275
Recv: 1436 in chunk, total bytes recv: 58711
Recv: 1436 in chunk, total bytes recv: 60147
Recv: 1436 in chunk, total bytes recv: 61583
Recv: 1436 in chunk, total bytes recv: 63019
Recv: 1436 in chunk, total bytes recv: 64455
Recv: 1436 in chunk, total bytes recv: 65891
Recv: 1436 in chunk, total bytes recv: 67327
Recv: 1436 in chunk, total bytes recv: 68763
Recv: 1436 in chunk, total bytes recv: 70199
Recv: 1436 in chunk, total bytes recv: 71635
Recv: 1436 in chunk, total bytes recv: 73071
Recv: 1436 in chunk, total bytes recv: 74507
Recv: 1436 in chunk, total bytes recv: 75943
Recv: 1436 in chunk, total bytes recv: 77379
Recv: 1436 in chunk, total bytes recv: 78815
Recv: 1436 in chunk, total bytes recv: 80251
Recv: 1436 in chunk, total bytes recv: 81687
Recv: 1436 in chunk, total bytes recv: 83123
Recv: 1436 in chunk, total bytes recv: 84559
Recv: 1436 in chunk, total bytes recv: 85995
Recv: 1436 in chunk, total bytes recv: 87431
Recv: 1436 in chunk, total bytes recv: 88867
Recv: 1436 in chunk, total bytes recv: 90303
Recv: 1436 in chunk, total bytes recv: 91739
Recv: 1436 in chunk, total bytes recv: 93175
Recv: 1436 in chunk, total bytes recv: 94611
Recv: 1436 in chunk, total bytes recv: 96047
Recv: 1436 in chunk, total bytes recv: 97483
Recv: 1436 in chunk, total bytes recv: 98919
Recv: 1436 in chunk, total bytes recv: 100355
Recv: 1436 in chunk, total bytes recv: 101791
Recv: 1436 in chunk, total bytes recv: 103227
Recv: 1436 in chunk, total bytes recv: 104663
Recv: 1436 in chunk, total bytes recv: 106099
Recv: 1436 in chunk, total bytes recv: 107535
Recv: 1436 in chunk, total bytes recv: 108971
Recv: 1436 in chunk, total bytes recv: 110407
Recv: 1436 in chunk, total bytes recv: 111843
Recv: 1436 in chunk, total bytes recv: 113279
Recv: 1436 in chunk, total bytes recv: 114715
Recv: 1436 in chunk, total bytes recv: 116151
Recv: 1436 in chunk, total bytes recv: 117587
Recv: 1436 in chunk, total bytes recv: 119023
Recv: 1436 in chunk, total bytes recv: 120459
Recv: 1436 in chunk, total bytes recv: 121895
Recv: 1436 in chunk, total bytes recv: 123331
Recv: 1436 in chunk, total bytes recv: 124767
Recv: 1436 in chunk, total bytes recv: 126203
Recv: 1436 in chunk, total bytes recv: 127639
Recv: 1436 in chunk, total bytes recv: 129075
Recv: 1436 in chunk, total bytes recv: 130511
Recv: 1436 in chunk, total bytes recv: 131947
Recv: 1436 in chunk, total bytes recv: 133383
Recv: 1436 in chunk, total bytes recv: 134819
Recv: 1436 in chunk, total bytes recv: 136255
Recv: 1436 in chunk, total bytes recv: 137691
Recv: 1436 in chunk, total bytes recv: 139127
Recv: 1436 in chunk, total bytes recv: 140563
Recv: 1436 in chunk, total bytes recv: 141999
Recv: 1436 in chunk, total bytes recv: 143435
Recv: 1436 in chunk, total bytes recv: 144871
Recv: 1436 in chunk, total bytes recv: 146307
Recv: 1436 in chunk, total bytes recv: 147743
Recv: 1436 in chunk, total bytes recv: 149179
Recv: 1436 in chunk, total bytes recv: 150615
Recv: 1436 in chunk, total bytes recv: 152051
Recv: 1436 in chunk, total bytes recv: 153487
Recv: 1436 in chunk, total bytes recv: 154923
Recv: 1436 in chunk, total bytes recv: 156359
Recv: 1436 in chunk, total bytes recv: 157795
Recv: 1436 in chunk, total bytes recv: 159231
Recv: 1436 in chunk, total bytes recv: 160667
Recv: 1436 in chunk, total bytes recv: 162103
Recv: 1436 in chunk, total bytes recv: 163539
Recv: 1436 in chunk, total bytes recv: 164975
Recv: 1436 in chunk, total bytes recv: 166411
Recv: 1436 in chunk, total bytes recv: 167847
Recv: 1436 in chunk, total bytes recv: 169283
Recv: 1436 in chunk, total bytes recv: 170719
Recv: 1436 in chunk, total bytes recv: 172155
Recv: 1436 in chunk, total bytes recv: 173591
Recv: 1436 in chunk, total bytes recv: 175027
Recv: 1436 in chunk, total bytes recv: 176463
Recv: 1436 in chunk, total bytes recv: 177899
Recv: 1436 in chunk, total bytes recv: 179335
Recv: 1436 in chunk, total bytes recv: 180771
Recv: 1436 in chunk, total bytes recv: 182207
Recv: 1436 in chunk, total bytes recv: 183643
Recv: 1436 in chunk, total bytes recv: 185079
Recv: 1436 in chunk, total bytes recv: 186515
Recv: 1436 in chunk, total bytes recv: 187951
Recv: 1436 in chunk, total bytes recv: 189387
Recv: 1436 in chunk, total bytes recv: 190823
Recv: 1436 in chunk, total bytes recv: 192259
Recv: 1436 in chunk, total bytes recv: 193695
Recv: 1436 in chunk, total bytes recv: 195131
Recv: 1436 in chunk, total bytes recv: 196567
Recv: 1436 in chunk, total bytes recv: 198003
Recv: 1436 in chunk, total bytes recv: 199439
Recv: 1436 in chunk, total bytes recv: 200875
Recv: 1436 in chunk, total bytes recv: 202311
Recv: 1436 in chunk, total bytes recv: 203747
Recv: 1436 in chunk, total bytes recv: 205183
Recv: 1436 in chunk, total bytes recv: 206619
Recv: 1436 in chunk, total bytes recv: 208055
Recv: 1436 in chunk, total bytes recv: 209491
Recv: 1436 in chunk, total bytes recv: 210927
Recv: 1436 in chunk, total bytes recv: 212363
Recv: 1436 in chunk, total bytes recv: 213799
Recv: 1436 in chunk, total bytes recv: 215235
Recv: 1436 in chunk, total bytes recv: 216671
Recv: 1436 in chunk, total bytes recv: 218107
Recv: 1436 in chunk, total bytes recv: 219543
Recv: 1436 in chunk, total bytes recv: 220979
Recv: 1436 in chunk, total bytes recv: 222415
Recv: 1436 in chunk, total bytes recv: 223851
Recv: 1436 in chunk, total bytes recv: 225287
Recv: 1436 in chunk, total bytes recv: 226723
Recv: 1436 in chunk, total bytes recv: 228159
Recv: 1436 in chunk, total bytes recv: 229595
Recv: 1436 in chunk, total bytes recv: 231031
Recv: 1436 in chunk, total bytes recv: 232467
Recv: 1436 in chunk, total bytes recv: 233903
Recv: 1436 in chunk, total bytes recv: 235339
Recv: 1436 in chunk, total bytes recv: 236775
Recv: 1436 in chunk, total bytes recv: 238211
Recv: 1436 in chunk, total bytes recv: 239647
Recv: 280 in chunk, total bytes recv: 239927

File Creation date wrong

Hello Thanks for this library I am using it in my Aquarium controller project but I have an issue on teh creation date of the files created on the USB somehow the date shows always 31.12.2003 time 23.00 is there a reason for that ?

Thanks
Charles
CH736Scapture

CH376 with SPI

i am using Arduino Mega With CH376 using SPI, but when i see the data frame using logic analiser it seems that i have no response,
just the same data i sent using SPI is return back again, i don't know if the problem in the connection or what , but i tried many configurations to the pins and still not working , and i need it because it is part from my graduation project.
i hope to help me fixing the problem, and thanks
114

for Zero SAMD

SetGet.cpp:

#ifndef dtostrf
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}
#endif

I removed a const somewhere

Tested, working.

Can it open .bin file and read byte ?

Hello thanks for the library and I use it in few of my projects to write text files and have no issues

Today I wanted to experiment if possible to use a USB drive to update Arduino directly from USB but I am not sure if Library can open .bin files and Read one byte at a time , Is that possible with the library.

The sd Library has has a function called readBytes

Regards
Charles

[SPI interface] USB is not detecting and Prints as Attach flash drive first!

I am using Arduino Uno borad and CH376S USB host module. And I have connected with SPI interface as shown in the following figure.
I didn't connect INT pin.
image

I was trying basicUsageSPI example but didn't work for me. On serial it was printing like as

*************************
Attach flash drive first!
*************************

Any suggestions?

Writing on file slowly!

Hi,
Thanks for your useful library.
I am trying to write my sensors data on file, but there is a long delay after each writing block (256 bytes), So I have to wait for the next ready(Done) from Ch376 for more than 3 milliseconds.
How much is the maximum speed for writing a file?

best regards.

Trying to use streamFile in ESP32's "webserver" library

Hello, i am trying to stream image from USB FLASH to my web, but it seems that this library is not constructed to use with webserver library. Is there workaround for this, or it needs to be implemented? Thank you.

Device ESP32 D1 R32 + Ch376s

-- Errors in Arduino IDE while compiling--

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WebServer\src/WebServer.h: In instantiation of 'size_t WebServer::streamFile(T&, const String&) [with T = Ch376msc; size_t = unsigned int]':

esp32-server-usb-test1\esp32-server-usb-test1.ino:355:45: required from here

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WebServer\src/WebServer.h:138:5: error: 'class Ch376msc' has no member named 'size'

 _streamFileCore(file.size(), file.name(), contentType);

 ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WebServer\src/WebServer.h:138:5: error: 'class Ch376msc' has no member named 'name'

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WebServer\src/WebServer.h:139:37: error: no matching function for call to 'WiFiClient::write(Ch376msc&)'

 return _currentClient.write(file);

                                 ^

In file included from
Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.h:37:0,

             from esp32-server-usb-test1\esp32-server-usb-test1.ino:3:

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:55:12: note: candidate: virtual size_t WiFiClient::write(uint8_t)

 size_t write(uint8_t data);

        ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:55:12: note: no known conversion for argument 1 from 'Ch376msc' to 'uint8_t {aka unsigned char}'

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:56:12: note: candidate: virtual size_t WiFiClient::write(const uint8_t*, size_t)

 size_t write(const uint8_t *buf, size_t size);

        ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:56:12: note: candidate expects 2 arguments, 1 provided

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:58:12: note: candidate: size_t WiFiClient::write(Stream&)

 size_t write(Stream &stream);

        ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiClient.h:58:12: note: no known conversion for argument 1 from 'Ch376msc' to 'Stream&'

In file included from
Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Stream.h:26:0,

             from 

Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:147,

             from sketch\esp32-server-usb-test1.ino.cpp:1:

Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.h:69:12: note: candidate: size_t Print::write(const char*, size_t)

 size_t write(const char *buffer, size_t size)

        ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.h:69:12: note: candidate expects 2 arguments, 1 provided

Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.h:61:12: note: candidate: size_t Print::write(const char*)

 size_t write(const char *str)

        ^

Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.h:61:12: note: no known conversion for argument 1 from 'Ch376msc' to 'const char*'

[Documentation]Jumper position?

Nice lib thank you so much for your work, I got hard time to find clear doc about CH376s using SPI until I saw your lib. soo happy

You write jumper configure the communication way (SPI/Serial)
but picture always show same position
Is that normal?

FYI I plan to use it on ESP32 and report back and eventually do a PR to add ESP32 in library.properties if it is ok

HID Lib to communicate with input peripherals: mouses, keyboards, gamepads, tablets, etc.

Hello, I saw that it is possible to use CH376 with HID devices, could anyone indicate any library?

I would like to use a keyboard.

I found these references:

http://en.pudn.com/Download/item/id/2056626.html

Description: CH376 operation of the mouse keyboard, can bus, device descriptor configuration descriptor, mouse, normal operation.

http://pulko.mandy.pagesperso-orange.fr/shinra/albireo.shtml

Practical case: driver for an HID mouse

Since the early developments on Albireo, things have changed a little in the CPC world and several other mass storage interfaces are now easily available. However, another problem was still not completely solved: there was not a simple solution for connecting a mouse to the CPC.

Of course, the Albireo USB port can drive any USB peripheral, including any standard USB mouse. It is no more needed to dig out a PS/2 compatible mouse for your Symbiface, or even worse, an Atari/Amiga one for the MutliPlay.

Moreover, the USB standard provides a rather high level view on events from the mouse, which makes implementing this with low CPU use possible (the mouse driver was initially written completely in BASIC, and if using assembler, an interrupt driven setup is possible, freeing most CPU cycles).

This also serves as an example of how USB communications are implemented with the CH376. It opens the possibility of writing drivers for more devices. Gamepads, printers, webcams... you name it.

The code in this section is written in BASIC-like syntax. This makes it easy to read for everyone.

moveCursor() working

I want to align 5 different types of data in a single notepad file, so am trying to use moveCursor() function but it's a bit confusing can you help me how to set the Cursor position on a notepad. You have mentioned that the value from (00000000h-ffffffffh) what does it means can you give one example?

Arduino Due not connecting to CH376

Hello, I have the CH376S module and I have installed this library. My board is an Arduino Due and I have followed the wiring diagram on this repo. However,my Arduino Due is not able to communicate with the module.

I have done some debugging I I find the library stays in the loop shown below in the "CheckIntMessage" function:

	} else {//spi
		while(!digitalRead(_intPin)){
			tmpReturn = getInterrupt(); // get int message
			delay(10);//sadly but it required for stability, sometime prior attaching drive the CH376 produce more interrupts
		}// end while
	}//end if interface

The library is initialized with:
Ch376msc flashDrive(10); // chipSelect

Advice on getting this working would be much appreciated.

H/W Serial on Zero/M0 ZERO ATSAMD21G18 = Attach flash drive first!

Please add to readme what D1 Led on the module does default wise? Should it be lit after init with library? Does it blink?

Does it light up when initializind the module is done? while reading it does what?

Okay so i did wire it up like suggested in the readme for my Arduino Zero and Hardware Serial

(MCU) --(Module)
(PIN0) -- (TXT) //alway cross TXD RXD
(PIN1) -- (RXD)
(D5) -- (GND)

Should give 115200 baudrate detached later for default baudrate. JUMPER left to Serial not Parallel

Test (1)
Ch376msc flashDrive(Serial1, 115200); //Ground Wire from D5 to GND on MCU Board
SerialUSB.begin(9600);
Outcome:
i do get the Serial output and can access the menue nothing more..
USB Stick is not recognized (4GB FAT32)
########
Test (2)
Ch376msc flashDrive(Serial1, 9600); // NO WIRE ON D5 Module - GND MCU
SerialUSB.begin(115200);

power off, usb stick attached
Red LED D1 constant lit after powercycle?
Still cant read or do anything :-/

Windows won't list created files and folders

Dear @djuseeq , thank you for this library!

I have a BluePill (STM32F103) and also a BlackPill (STM32F401). My CH376 module is the same as yours.

For now I am using BluePill with the Arduino_Core_STM32 (by stm32duino) and it worked with no effort for the basicUsageHwSerial example! I am using HardwareSerial Serial2 on pins PA2 and PA3:

#include <Ch376msc.h>
HardwareSerial Serial2(PA3, PA2);
Ch376msc flashDrive(Serial2, 115200);

The example code worked creating, appending and reading a file. It also apears to have worked creating and opening folders.

The problem is when I connect the pendrive to my computer. It appears as empty although Windows shows that some space is used on it.

I changed the example a bit and created 1000 files and was able to list the files using the module. But again, when I put the pendrive on my computer the device has no file in it, only more space is used.

I tried with an USB card reader and also with an actuall USB flash drive (pendrive).
For the USB card reader I tried formatting with FAT16 and also FAT32, for the pendrive I used only FAT32 format.
Exactly same behavior on both devices.

Any files I create in Windows also are not listed by the module. Apparently one time a file showed up in list (7) but its name was garbled.

Can you help me? Do you know what could be the problem?

Problem sharing SPI

SPI.begin();
flashDrive.init();
delay(1000);
if(flashDrive.checkDrive()) tft.println("Ch376 ok");
else tft.println("Ch376 fail");

If i add SPI.beghin() It does not work anymore
But if you do not add other devices do not work. SD, TFT, ecc.
Questo perchè uso i PIN SPI anche per IO Shif register.

void updateIO() // 74HC595 Output + 74HC165 Input
{
digitalWrite(latchPinI, LOW);
digitalWrite(latchPinO, LOW);
pinMode(clockPin, OUTPUT);
pinMode(dataPinO, OUTPUT);
shiftOut(dataPinO, clockPin, MSBFIRST, OutReg);
digitalWrite(latchPinO, HIGH);
SPI.begin();
}

Can't get SPI to work

Hi. I have my CH376 module connected to an Arduino Leonardo (ATmega 32u4), with BUSY configured on D9, and CS on D10 (which is the defaults in the example code).

When I run the SPI example code, I can see that it is communicating as it enables USB detection; when i have my thumb drive plugged in, the LED on my CH376 breakout board is lit, when i remove it, it is not lit.

I have used this same drive and same interface board in UART mode, which worked fine, but my needs changed and I need to use SPI mode. When I had it working in UART mode, I knew it was configured right when i sent the USB MODE command, which resulted in the LED being lit in this way...

So I know that the CH376 is receiving the data, but every example responds with "Attach flash drive first!"

Deleting a file in a sub-directory deletes said directory

Using the snippet below deletes the entire DIR2 subdirectory.

Looking that the datasheet it seems that the file needs to be opened before deleting, otherwise the entire directory is deleted. I'm not sure if this would be classified as a bug, since deleting a folder has the same command (as far as the CH376s is concerned). Maybe adding some info to README.md would be helpful for others.

I spent a bit tearing my hair out trying to figure out what was going on. Hope this helps others.

Deletes Sub-Directory

flashDrive.cd("/DIR1/DIR2", 0);
flashDrive.setFileName("TEXT.TXT");
flashDrive.deleteFile();

Deletes File

flashDrive.cd("/DIR1/DIR2", 0);
flashDrive.setFileName("TEXT.TXT");
flashDrive.openFile();
flashDrive.deleteFile();

Jumper position error?

Is there an error in the jumper position diagram for changing between uart and spi mode? Appears the jumper remains in either the serial or the spi position no matter which is in use.

Force USB presence detection

I am experiencing inconsistent behaviour from .checkDrive().

I am building an Arduino data logger which has three softserial ports. One of these is for the CH376. The other two are for devices that give me data. The built-in (hardware) serial port is hooked up to a PC (via USB) for debugging.

If I call .checkDrive() at startup I can reliably detect that a memory stick is or is not present. If I call it again later then it doesn't reliably report that the memory stick is or is not present. I wonder if it's because I am switching to the other softserial ports (using .listen()) in between using the CH376 softserial port? I always use .listen() to select the CH376 softserial port before doing any CH376 operations.

Is there a way to force the Ch376msc object to start from scratch? Or a way to reset its status so I can call .checkDrive() again?

Before writing the log file I call .checkDrive(). If I start my data logger with a memory stick inserted then I can write files reliably. But, if I take out the memory stick the program will still try to write files because .checkDrive() returns true.

If I start my data logger without a memory stick inserted then I can't write files because .checkDrive() returns false . But, if I insert the memory stick the program will still not write files because .checkDrive() still returns false.

Your test program works properly. I can insert and remove the memory stick and the test software will detect the current state. When your test program is running or my program is running the indicator LED on the CH376 board turns on and off correctly when the memory stick is installed or removed. But, when I call .checkDrive() in my program it doesn't report the current state properly. What am I missing? Do you have any suggestions for debugging? Thanks.

file name Limitations

hi dear György Kovács
and thanks for your nice code!
a question!
why file name must have 8 capitalized char ?
is there any way to solve this Limitations?
as far as i know sd cards dos not have this limitation.

Maximum baud rate speed of HardwareSerial

Hi
Is what maximum baud rate speed of HardwareSerial?, I need use 250000 , is it possible ?
I try to set baud rate to 250000 and set D6 to LOW but i don't work.

 //UART
 //For hardware serial leave the communication settings on the module at default speed (9600bps) 
 Ch376msc(HardwareSerial, speed);//Select the serial port to which the module is connected and the desired speed(9600, 19200, 57600, 115200)

Add Test for chip presence

Add Test for chip presence

And what difference from driveReady() and checkDrive() ?
Always boot true if flash in, and boot false in the absence of flash

  if(flashDrive.init()) SerialUSB.println("Chip Ok");      
  else SerialUSB.println("Chip fail");
  
  if(flashDrive.driveReady()) SerialUSB.println("driveReady Ok");      
  else SerialUSB.println("driveReady fail");
   
  if(flashDrive.checkDrive()) SerialUSB.println("checkDrive Ok");      
  else SerialUSB.println("checkDrive fail");

/////////////////////////////////////////////////////////////////
bool Ch376msc::init(){
.....	return _controllerReady;
}

Append to new file

I thought I had broken things when I decided that appending to a new file was the same as appending to an existing file. It seems to me that it should be. However, if I try to do this I end up with a corrupt filename. You can reproduce this by running the test code and selecting option 2:Append without first selecting option 1:Create.

I am writing a log file to the USB drive. I want to append continuously to the log file, but I need to handle the case where the drive is blank at first, or if someone removes the USB drive with the log file on it and inserts a new one with no file on it. This means that every time it is time to write to the log I must first check if the file exists, then create it and write to it if it doesn't exist, or move the cursor to the end and write to it if it does exist. This is cumbersome, but then, so is everything in the programming world.

What I want to do is openFile(), moveCursor(CURSOREND), then writeFile() every time. If the file is new it will be created and will be empty, and moveCursor() will essentially do nothing. Is this possible? I hope so.

Thanks for the great library!

DELETE EVERY SINGLE BIT

HI DEAR
FIRST, I WANT TO ASK YOU IS THERE ANY WAY TO CLEAR EVERY SINGLE BIT ?
SECOND IS THERE ANY WAY TO CHANGE FORMAT ? FAT 12 TO FAT16 OR FAT32 TO NTFS

Variable Naming conflicts with core ESP32 Variables:

:\Users\user\Documents\Arduino\libraries\Ch376msc-master\src/CommDef.h:262:15: error: 'const uint8_t ERR_TIMEOUT' redeclared as different kind of symbol

 const uint8_t ERR_TIMEOUT = 0x02;

               ^

In file included from C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4/tools/sdk/include/lwip/lwip/pbuf.h:42:0,

                 from C:\Users\user\Documents\Arduino\libraries\AsyncTCP-master\src/AsyncTCP.h:30,

                 from C:\Users\user\AppData\Local\Temp\arduino_build_953027\sketch\webserver.h:1,

                 from C:\Users\user\Documents\OPENBUILDS-ENGINEER\PCB-Grbl-Touchscreen\PCB-Grbl-InterFace\Arduino Sketches\CapTouch_Beep_LEDs_with_LCD_GrblParser\CapTouch_Beep_LEDs_with_LCD_GrblParser.ino:16:

C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4/tools/sdk/include/lwip/lwip/err.h:69:3: note: previous declaration 'err_enum_t ERR_TIMEOUT'

   ERR_TIMEOUT    = -3,

   ^


const uint8_t ERR_TIMEOUT = 0x02;
from CommDef.h - can it be renamed to something else please ? It conflicts with https://github.com/espressif/arduino-esp32/blob/96822d783f3ab6a56a69b227ba4d1a1a36c66268/tools/sdk/include/lwip/lwip/err.h#L69

Can't compile (: - and I think core files get preference (:

STM32F103CBT6 - Blue Pill - Support

Has anyone successfully tested this library with STM32?

It worked with Arduino Nano, but it didn't work with Blue Pill.

The SPI port signal seems to be working, the ACT LED lights up when the flash drive is inserted, but the library prompts you to insert the flash drive even with the flash drive inserted and the ACT LED lit. ("Attach flash drive first!")

The SPI port has no other devices.

MIDI

Hi

Is it possible sent MIDI data from Ch376 via TX from Arduino to USB MIDI iNTERFACE?
IMG_4458

Thanks
Tomasz

CH376 Library MoveCursor issue

Hi,
i use the library with Arduino UNO reading a text file from disk on key (DOK).
while reading the file with example everything is great.
i am trying to read a section from the file using MoveCursor. i noticed that it works fine until a point where the byte address is close to 512 byte area in the file and so on - 1024, and multiplications of 512. at this point i am getting part of the correct data from the file and after 512 location it seems to get the first bytes of the file.
is it a bug?
am i doing something wrong?
thanks

getChipVer() returns 0xFF, but everything else works

Hi, just playing around, and noticed getChipVer() returns 0xff (not 0x43 or 0x42 as the Readme says it should)
Everything else works great (can read files, create files, browse directorys, etc - comms all working with the chip, just that one function that returns an odd result.

how to read serial write to usb flash drive?

Hi
I need to read data from serial port then write all to usb flash drive
my data send from pc around 1000 line like below

"0001:  2021-03-09 15:31:56 G001 3333 mv 127.36\r\n"
 |
 |
"1000:  2021-03-09 15:31:56 G001 3333 mv 127.36\r\n"

but It isn't written at all line , it is written around 5-10 line only.
this is my code , could you advise me ?
**so sorry about my english.

SoftwareSerial mySerial(7, 6);//  CH376S
String inputString = ""; 
bool stringComplete = false; 
//-------- setup ---------//
void setup() {
  Serial.begin(9600);
  mySerial.begin(115200);
}
//-------- Serial monitoring  ---------//
void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;    
    }   
  }
}
//------- void loop ---------//
void loop() {
 if(stringComplete){
   // prepare string to char
     int str_len = inputString.length() + 1; 
     char char_array[str_len];
     inputString.toCharArray(char_array, str_len);

     flashDrive.setFileName("REPORT.TXT");  //set the file name
        if(flashDrive.openFile() == ANSW_USB_INT_SUCCESS){  //open the file
         flashDrive.moveCursor(CURSOREND);     //if the file exist, move the "virtual" cursor at end of the file
        }
       // write to wire
       flashDrive.writeFile(char_array, strlen(char_array)); 
       flashDrive.closeFile(); 
      // clear data
       inputString =";
       stringComplete = false;
}

}

Donate Link (:

Do you have any way for us to buy you a coffee, or contribute towards your work? As a token of appreciation for this awesome library (:

Enhancement request: Stream or File support

So I can use writeStream from https://github.com/espressif/arduino-esp32/blob/master/libraries/Update/examples/SD_Update/SD_Update.ino (:

Other example: https://techtutorialsx.com/2019/07/21/esp32-arduino-updating-firmware-from-the-spiffs-file-system/

Between the examples, SD and SPIFFS covered, no if only CH376s library had a stream interface (;

[alternative, I am far to stupid to figure out hehe, is to use https://github.com/espressif/arduino-esp32/blob/master/libraries/Update/src/Update.h#L46-L50

ch376s not working with esp32

i try to run ch376 use module with SPI interface , i m using esp32 controller, i try but not succeed, i littel bit consue about connection hai jumper setting related to spi. plz give me connection diagram and, example code.

WR > GND
RD > GND
CS > 3V3
D7 > pin_spi_miso= esp32 ->D19
D6 > pin_spi_mosi= esp32 ->D23
D5 > pin_spi_sck = esp32 ->D18
D3 > pin_ch376_cs= esp32 ->D5
INT > pin_ch376_int =NOT USE
Ch376msc flashDrive(5);
I USE THIS SETTING.

ESP32: Attach flash/SD drive first! - how can I help debug (:

I have an CH376S hooked up to an ESP32 via SPI.
Example sketches compile fine, but cannot read from USB drive: "Attach flash/SD drive first!"

If there is anything I can do to help you get it supported on ESP32 (or am I just being stupid, I have the correct CS pin wired/assigned)

Schematic (own board)
schematic

INT is connected, CS is connected, and MISO/MOSI/SCLK

Instanced as Ch376msc flashDrive(4, 14); // chipSelect, interrupt pin to work with Interrupt pin, as bus is shared

LED on board lights up when I plug in flash drive, goes out when unplugged

Does "Attach flash/SD drive first! " error (from example) mean cannot find USB, or also SPI comms error?

info needed

Hello I would like to know if anyone has a working example for Json read and write files with this library

Thanks

Request

First, I want to thank you for this library. I also used Scott C example code. Scott C code can create the file but can not read in computer. Then I found your library with improvement of Scott C codes.

I saw your code added FAT file structure. Is it FAT32 file structure or other? I have not seen those types and size variable in this link https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system.

was it the problem in Scott C example code? (FAT file structure not included in Scott C example code).

What are other possible extensions to save files in pen drive? (Other than txt and csv)

If we add NTFS file structure, can not we save files? Like you add FAT32 file structure

I keep getting "Attach Flash Drive First" message

After connecting to Arduino as described in the "SoftwareSerial" example sketch,

I get the menu -- but when I type any input, it says "Attach Flash Drive First"

I have tried three different USB Flash Drives and same error appears.

Read .csv file from flash drive

Hi,
I am working with the updated CH376msc library.
I tried to read a csv (type of Excel) file from flash drive using the library example, but no success.
After i changed the file extension on flash drive to TXT - everything work just great.
A .csv file is actually kind of text file where data is comma delimited.
Why it is not possible to read other files that are not TXT type?
Is there any way that will enable read other file types?
Thanks

CH376s SPI USB issues

Discussed in #62

Originally posted by al789b January 13, 2022
Hi ,

I'm having some issues with wiring the chip up to my Arduino Nano/Uno following the diagram provided. I want to use SPI to read & write to a USB drive, so followed the schematic provided for SPI, but I'm sure its not detecting when the drive has been plugged in. When using the example sketch the serial monitor would return the firmware version (68) when using getChipVer(), but cannot talk to the USB drive. I doubt it is an issue with the code.

Even when I don't try to use the SPI connections but just the 5V, 3V3 and GND connections shown, I can't get the LED to light up without manually connecting it to ground with a jumper, so there may be something wrong with the wiring? Then I tried it with the other 6 CH376 modules I have and get the same issue, whether I use the Nano or Uno+logic shifter.

For the record I can't get a response using UART wiring & sketches either..

Is it likely that all of them are poorly made or am I missing something obvious? Has anyone else had a similar issue?
Any suggestions would be much appreciated. TIA :)

CH376_SPI_SIMPLE

CH376_Nano_SPI_wiring

writeFile(buff, len) doesn't work reliably.

Files are left with a single character written. Logically implementing the same code using writeChar(char) gives the desired result.
Felt I should through some light on it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.