├── Arduino Language Reference.pdf ├── CH340_341_for_win10_winxp ├── CH340_341.EXE └── CH341SER.EXE ├── CH341SER_LINUX └── CH341SER_LINUX │ ├── Makefile │ ├── ch34x.c │ └── readme.txt ├── CH341SER_for_64bit_win7 └── CH341SER │ ├── CH341PT.DLL │ ├── CH341S64.SYS │ ├── CH341S98.SYS │ ├── CH341SER.INF │ ├── CH341SER.SYS │ ├── CH341SER.VXD │ ├── DRVSETUP64 │ └── DRVSETUP64.exe │ ├── SETUP.EXE │ └── ch341SER.CAT ├── CH34XUSB-SERIAL_for_mac ├── CH34x_Install_V1.3.pkg └── Readme.pdf ├── How to start.pdf ├── Lesson1-LED Running Lights ├── LED Running Lights.pdf └── LED_Running_Lights │ └── LED_Running_Lights.ino ├── Lesson10-LM35Temperature Sensor ├── LM35 │ └── LM35.ino ├── LM35Temperature Sensor.pdf └── LM35_datasheet.pdf ├── Lesson11-L293D for a DC Motor ├── L293D for a DC Motor.pdf ├── L293D-DataSheet.pdf └── motor │ └── motor.ino ├── Lesson12-Servo Motor ├── Servo Motor.pdf └── Servo │ └── Servo.ino ├── Lesson2-Photosensitive Resistorr ├── Photosensitive Light Experiment.pdf └── photosensitive │ └── photosensitive.ino ├── Lesson3-Button ├── Button.pdf └── Button │ └── Button.ino ├── Lesson4-PWM ├── PWM.pdf └── pwm │ └── pwm.ino ├── Lesson5-RGB breathing light ├── RGB LED.pdf ├── RGB │ └── RGB.ino └── RGB_Breathing_Light │ └── RGB_Breathing_Light.ino ├── Lesson6-Buzzer ├── Buzzer.pdf └── buzzer │ └── buzzer.ino ├── Lesson7-Flame Sensor ├── Flame Sensor.pdf └── Flame_sensor │ └── Flame_sensor.ino ├── Lesson8-SW520D ├── SW520D Vibration Switch.pdf └── SW520D │ └── SW520D.ino ├── Lesson9-4-Digit8-Segment Display ├── 4-Digit 8-Segment Display.pdf ├── LM35+_4-8Segment_Display │ └── demo │ │ └── demo.ino ├── _4x7Segment_Display │ └── _4x8Segment_Display.ino └── _4x8Segment_Display1 │ └── _4x8Segment_Display1.ino ├── NanoSchematic.pdf ├── README.md └── image ├── Download.png └── Image.png /Arduino Language Reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Arduino Language Reference.pdf -------------------------------------------------------------------------------- /CH340_341_for_win10_winxp/CH340_341.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH340_341_for_win10_winxp/CH340_341.EXE -------------------------------------------------------------------------------- /CH340_341_for_win10_winxp/CH341SER.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH340_341_for_win10_winxp/CH341SER.EXE -------------------------------------------------------------------------------- /CH341SER_LINUX/CH341SER_LINUX/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(KERNELRELEASE), ) 2 | KERNELDIR := /lib/modules/$(shell uname -r)/build 3 | PWD :=$(shell pwd) 4 | default: 5 | $(MAKE) -C $(KERNELDIR) M=$(PWD) 6 | clean: 7 | rm -rf .tmp_versions Module.symvers *.mod.c *.o *.ko .*.cmd Module.markers modules.order 8 | load: 9 | modprobe usbserial 10 | insmod ch34x.ko 11 | unload: 12 | rmmod ch34x 13 | else 14 | obj-m := ch34x.o 15 | endif 16 | -------------------------------------------------------------------------------- /CH341SER_LINUX/CH341SER_LINUX/ch34x.c: -------------------------------------------------------------------------------- 1 | // 2013.7 2 | //******************************************** 3 | //** Copyright (C) WCH 2002-2013 ****** 4 | //** Web: http://www.winchiphead.com ****** 5 | //******************************************** 6 | //** Driver for USB to serial adaptor CH34X** 7 | //** GCC ** 8 | //******************************************** 9 | 10 | // Support linux kernel version 2.6.25 and later 11 | // 12 | 13 | #include 14 | #ifndef KERNEL_VERSION 15 | #define KERNEL_VERSION(ver, rel, seq) ((ver << 16) | (rel << 8) | (seq)) 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | //#include 31 | #include 32 | #include 33 | 34 | #define DRIVER_DESC "WCH CH34x USB to serial adaptor driver" 35 | #define DRIVER_AUTHOR "" 36 | 37 | #define CH34x_VENDOR_ID 0x1A86 38 | #define CH340_PRODUCT_ID 0x7523 39 | #define CH341_PRODUCT_ID 0x5523 40 | 41 | #define CH34x_CLOSING_WAIT (30 * HZ) 42 | 43 | #define CH34x_BUF_SIZE 1024 44 | #define CH34x_TMP_BUF_SIZE 1024 45 | 46 | //Vendor define 47 | #define VENDOR_WRITE_TYPE 0x40 48 | #define VENDOR_READ_TYPE 0xC0 49 | 50 | #define VENDOR_READ 0x95 51 | #define VENDOR_WRITE 0x9A 52 | #define VENDOR_SERIAL_INIT 0xA1 53 | #define VENDOR_MODEM_OUT 0xA4 54 | #define VENDOR_VERSION 0x5F 55 | 56 | //For CMD 0xA4 57 | #define UART_CTS 0x01 58 | #define UART_DSR 0x02 59 | #define UART_RING 0x04 60 | #define UART_DCD 0x08 61 | #define CONTROL_OUT 0x10 62 | #define CONTROL_DTR 0x20 63 | #define CONTROL_RTS 0x40 64 | 65 | //Uart state 66 | #define UART_STATE 0x00 67 | #define UART_OVERRUN_ERROR 0x01 68 | #define UART_BREAK_ERROR //no define 69 | #define UART_PARITY_ERROR 0x02 70 | #define UART_FRAME_ERROR 0x06 71 | #define UART_RECV_ERROR 0x02 72 | #define UART_STATE_TRANSIENT_MASK 0x07 73 | 74 | //Port state 75 | #define PORTA_STATE 0x01 76 | #define PORTB_STATE 0x02 77 | #define PORTC_STATE 0x03 78 | 79 | //CH34x Baud Rate 80 | #define CH34x_BAUDRATE_FACTOR 1532620800 81 | #define CH34x_BAUDRATE_DIVMAX 3 82 | 83 | //#define DEBUG_CH34x 84 | #undef DEBUG_CH34x 85 | 86 | #ifdef DEBUG_CH34x 87 | #define dbg_ch34x( format, arg... ) \ 88 | printk( KERN_DEBUG "%d: " format "\n", __LINE__, ##arg ) 89 | #else 90 | #define dbg_ch34x( format, arg... ) \ 91 | do{ \ 92 | if(0) \ 93 | printk(KERN_DEBUG "%d: " format "\n", __LINE__, ##arg); \ 94 | } while (0) 95 | #endif 96 | 97 | #ifdef DEBUG_CH34x 98 | #define err_ch34x( format, arg... ) \ 99 | printk(KERN_ERR KBUILD_MODNAME ": " format "\n", ##arg) 100 | #else 101 | #define err_ch34x( format, arg... ) \ 102 | do{ \ 103 | if(0) \ 104 | printk( KERN_ERR KBUILD_MODNAME ": " format "\n", ##arg)\ 105 | }while(0) 106 | #endif 107 | 108 | // For debug 109 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,1)) 110 | static int debug = 1; 111 | #endif 112 | 113 | static DECLARE_WAIT_QUEUE_HEAD(wq); 114 | static int wait_flag = 0; 115 | 116 | struct ch34x_buf { 117 | unsigned int buf_size; 118 | char *buf_buf; 119 | char *buf_get; 120 | char *buf_put; 121 | }; 122 | 123 | struct ch34x_private { 124 | spinlock_t lock; //access lock 125 | struct ch34x_buf *buf; 126 | int write_urb_in_use; 127 | unsigned baud_rate; 128 | wait_queue_head_t delta_msr_wait; 129 | u8 line_control; 130 | u8 line_status; 131 | u8 termios_initialized; 132 | }; 133 | 134 | static struct usb_device_id id_table [] = { 135 | { USB_DEVICE(CH34x_VENDOR_ID, CH340_PRODUCT_ID) }, 136 | { USB_DEVICE(CH34x_VENDOR_ID, CH341_PRODUCT_ID) }, 137 | { } //End 138 | }; 139 | MODULE_DEVICE_TABLE( usb, id_table ); 140 | 141 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,2)) 142 | static struct usb_driver ch34x_driver = { 143 | .name = "ch34x", 144 | .probe = usb_serial_probe, 145 | .disconnect = usb_serial_disconnect, 146 | .id_table = id_table, 147 | .suspend = usb_serial_suspend, 148 | .resume = usb_serial_resume, 149 | .no_dynamic_id = 1, 150 | .supports_autosuspend = 1, 151 | }; 152 | #endif 153 | 154 | // ch34x_buf_alloc 155 | // Allocate a circular buffer and all associated memory 156 | static struct ch34x_buf *ch34x_buf_alloc( unsigned int size ) 157 | { 158 | struct ch34x_buf *pb; 159 | 160 | if( size == 0 ) 161 | return NULL; 162 | 163 | pb = kmalloc( sizeof(struct ch34x_buf), GFP_KERNEL ); 164 | if( pb == NULL ) 165 | return NULL; 166 | 167 | pb->buf_buf = kmalloc( size, GFP_KERNEL ); 168 | if( pb->buf_buf == NULL ) { 169 | kfree(pb); 170 | return NULL; 171 | } 172 | 173 | pb->buf_size = size; 174 | pb->buf_get = pb->buf_put = pb->buf_buf; 175 | 176 | return pb; 177 | } 178 | 179 | // ch34x_buf_free 180 | // Free the buffer and all associated memory 181 | static void ch34x_buf_free( struct ch34x_buf *pb ) 182 | { 183 | if( pb ) { 184 | kfree( pb->buf_buf ); 185 | kfree( pb ); 186 | } 187 | } 188 | 189 | // ch34x_buf_clear 190 | // Clear out all data in the circular buffer 191 | static void ch34x_buf_clear( struct ch34x_buf *pb ) 192 | { 193 | if( pb != NULL ) 194 | pb->buf_get = pb->buf_put; 195 | // equivalent to a get of all data available 196 | } 197 | 198 | // ch34x_buf_data_avail 199 | // Return the number of bytes of data available in he circular buffer 200 | static unsigned int ch34x_buf_data_avail( struct ch34x_buf *pb ) 201 | { 202 | if( pb == NULL ) 203 | return 0; 204 | 205 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size ); 206 | } 207 | 208 | // ch34x_buf_space_avail 209 | // Return the number of bytes of space available in the circular 210 | static unsigned int ch34x_buf_space_avail( struct ch34x_buf *pb ) 211 | { 212 | if( pb == NULL ) 213 | return 0; 214 | 215 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size ); 216 | } 217 | 218 | // ch34x_buf_put 219 | // Copy data from a user buffer and put it into the circular buffer. 220 | // Restrict to the amount of space available 221 | // Return the number of bytes copied 222 | static unsigned int ch34x_buf_put( struct ch34x_buf *pb, 223 | const char *buf, unsigned int count ) 224 | { 225 | unsigned int len; 226 | 227 | if( pb == NULL ) 228 | return 0; 229 | 230 | len = ch34x_buf_space_avail(pb); 231 | if( count > len ) 232 | count = len; 233 | else if( count == 0 ) 234 | return 0; 235 | 236 | len = pb->buf_buf + pb->buf_size - pb->buf_put; 237 | if( count > len ) { 238 | memcpy( pb->buf_put, buf, len ); 239 | memcpy( pb->buf_buf, buf+len, count - len ); 240 | pb->buf_put = pb->buf_buf + count - len; 241 | } 242 | else { 243 | memcpy( pb->buf_put, buf, count ); 244 | if( count < len ) 245 | pb->buf_put += count; 246 | else if( count == len ) 247 | pb->buf_put = pb->buf_buf; 248 | } 249 | 250 | return count; 251 | } 252 | 253 | static unsigned int ch34x_buf_get( struct ch34x_buf *pb, 254 | char *buf, unsigned int count ) 255 | { 256 | unsigned int len; 257 | 258 | if( pb == NULL ) 259 | return 0; 260 | 261 | len = ch34x_buf_data_avail(pb); 262 | if( count > len ) 263 | count = len; 264 | else if( count == 0 ) 265 | return 0; 266 | 267 | len = pb->buf_buf + pb->buf_size - pb->buf_get; 268 | if( count > len ) { 269 | memcpy( buf, pb->buf_get, len ); 270 | memcpy( buf+len, pb->buf_buf, count - len ); 271 | pb->buf_get = pb->buf_buf + count - len; 272 | } 273 | else { 274 | memcpy( buf, pb->buf_get, count ); 275 | if( count < len ) 276 | pb->buf_get += count; 277 | else if( count == len ) 278 | pb->buf_get = pb->buf_buf; 279 | } 280 | 281 | return count; 282 | } 283 | 284 | static int ch34x_vendor_read( __u8 request, 285 | __u16 value, 286 | __u16 index, 287 | struct usb_serial *serial, 288 | unsigned char *buf, 289 | __u16 len ) 290 | { 291 | int retval; 292 | 293 | retval = usb_control_msg( serial->dev, usb_rcvctrlpipe(serial->dev, 0), 294 | request, VENDOR_READ_TYPE, value, index, buf, len, 1000 ); 295 | dbg_ch34x("0x%x:0x%x:0x%x:0x%x %d - %d", 296 | VENDOR_READ_TYPE, request, value, index, retval, len ); 297 | 298 | return retval; 299 | } 300 | 301 | static int ch34x_vendor_write( __u8 request, 302 | __u16 value, 303 | __u16 index, 304 | struct usb_serial *serial, 305 | unsigned char *buf, 306 | __u16 len ) 307 | { 308 | int retval; 309 | 310 | retval = usb_control_msg( serial->dev, 311 | usb_sndctrlpipe(serial->dev, 0), 312 | request, 313 | VENDOR_WRITE_TYPE, 314 | value, index, buf, len, 1000 ); 315 | 316 | return retval; 317 | } 318 | 319 | static int set_control_lines( struct usb_serial *serial, 320 | u8 value ) 321 | { 322 | int retval; 323 | 324 | retval = ch34x_vendor_write( VENDOR_MODEM_OUT, (unsigned short)value, 325 | 0x0000, serial, NULL, 0x00 ); 326 | dbg_ch34x("%s - value=%d, retval=%d", __func__, value, retval ); 327 | 328 | return retval; 329 | } 330 | 331 | static int ch34x_get_baud_rate( unsigned int baud_rate, 332 | unsigned char *factor, unsigned char *divisor) 333 | { 334 | unsigned char a; 335 | unsigned char b; 336 | unsigned long c; 337 | 338 | switch ( baud_rate ) { 339 | case 921600: 340 | a = 0xf3; 341 | b = 7; 342 | break; 343 | case 307200: 344 | a = 0xd9; 345 | b = 7; 346 | break; 347 | default: 348 | if ( baud_rate > 6000000/255 ) { 349 | b = 3; 350 | c = 6000000; 351 | } else if ( baud_rate > 750000/255 ) { 352 | b = 2; 353 | c = 750000; 354 | } else if (baud_rate > 93750/255) { 355 | b = 1; 356 | c = 93750; 357 | } else { 358 | b = 0; 359 | c = 11719; 360 | } 361 | a = (unsigned char)(c / baud_rate); 362 | if (a == 0 || a == 0xFF) return -EINVAL; 363 | if ((c / a - baud_rate) > (baud_rate - c / (a + 1))) 364 | a ++; 365 | a = 256 - a; 366 | break; 367 | } 368 | *factor = a; 369 | *divisor = b; 370 | return 0; 371 | } 372 | 373 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 374 | static void ch34x_set_termios( struct tty_struct *tty, 375 | struct usb_serial_port *port, struct ktermios *old_termios ) 376 | { 377 | #else 378 | static void ch34x_set_termios( struct usb_serial_port *port, 379 | struct ktermios *old_termios ) 380 | { 381 | struct tty_struct *tty = port->tty; 382 | #endif 383 | struct usb_serial *serial = port->serial; 384 | struct ch34x_private *priv = usb_get_serial_port_data(port); 385 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,1)) //sure 386 | struct ktermios *termios = &tty->termios; 387 | #else 388 | struct ktermios *termios = tty->termios; 389 | #endif 390 | unsigned int baud_rate; 391 | unsigned int cflag; 392 | unsigned long flags; 393 | u8 control; 394 | 395 | unsigned char divisor = 0; 396 | unsigned char reg_count = 0; 397 | unsigned char factor = 0; 398 | unsigned char reg_value = 0; 399 | unsigned short value = 0; 400 | unsigned short index = 0; 401 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 402 | dbg_ch34x("%s - port:%d", __func__, port->number); 403 | #else 404 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 405 | #endif 406 | 407 | spin_lock_irqsave( &priv->lock, flags ); 408 | if( !priv->termios_initialized ) { 409 | *(termios) = tty_std_termios; 410 | termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 411 | termios->c_ispeed = 9600; 412 | termios->c_ospeed = 9600; 413 | priv->termios_initialized = 1; 414 | } 415 | spin_unlock_irqrestore( &priv->lock, flags ); 416 | 417 | /* 418 | * The ch34x is reported to lose bytes if you change serial setting 419 | * even to the same vaules as before. Thus we actually need to filter 420 | * in this specific case. 421 | */ 422 | if( !tty_termios_hw_change(termios, old_termios) ) 423 | return; 424 | 425 | cflag = termios->c_cflag; 426 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 427 | dbg_ch34x("%s (%d) cflag=0x%x\n", __func__, port->number, cflag); 428 | #else 429 | dbg_ch34x("%s (%d) cflag=0x%x\n", __func__, port->port_number, cflag); 430 | #endif 431 | // Get the byte size 432 | switch( cflag & CSIZE ) 433 | { 434 | case CS5: 435 | reg_value |= 0x00; 436 | break; 437 | case CS6: 438 | reg_value |= 0x01; 439 | break; 440 | case CS7: 441 | reg_value |= 0x02; 442 | break; 443 | case CS8: 444 | reg_value |= 0x03; 445 | break; 446 | default: 447 | reg_value |= 0x03; 448 | break; 449 | } 450 | dbg_ch34x("%s - data bits = %d", __func__, reg_value + 0x05 ); 451 | 452 | // Figure out the stop bits 453 | if( cflag & CSTOPB ) { 454 | reg_value |= 0x04; 455 | dbg_ch34x("%s - stop bits = 2", __func__); 456 | } 457 | else 458 | dbg_ch34x("%s - stop bits = 1", __func__); 459 | 460 | // Determine the parity 461 | if (cflag & PARENB) { 462 | if (cflag & CMSPAR) { 463 | if (cflag & PARODD) { 464 | reg_value |= (0x28 | 0x00); 465 | dbg_ch34x("%s - parity = mark", __func__); 466 | } else { 467 | reg_value |= (0x38 | 0x10); 468 | dbg_ch34x("%s - parity = space", __func__); 469 | } 470 | } else { 471 | if (cflag & PARODD) { 472 | reg_value |= (0x08 | 0x00); 473 | dbg_ch34x("%s - parity = odd", __func__); 474 | } else { 475 | reg_value |= (0x18 | 0x10); 476 | dbg_ch34x("%s - parity = even", __func__); 477 | } 478 | } 479 | } 480 | else 481 | dbg_ch34x("%s - parity = none", __func__); 482 | 483 | // Determine the baud rate 484 | baud_rate = tty_get_baud_rate( tty ); 485 | dbg_ch34x("%s = baud_rate = %d", __func__, baud_rate); 486 | ch34x_get_baud_rate( baud_rate, &factor, &divisor ); 487 | dbg_ch34x("----->>>> baud_rate = %d, factor:0x%x, divisor:0x%x", 488 | baud_rate, factor, divisor ); 489 | 490 | //enable SFR_UART RX and TX 491 | reg_value |= 0xc0; 492 | //enable SFR_UART Control register and timer 493 | reg_count |= 0x9c; 494 | 495 | value |= reg_count; 496 | value |= (unsigned short)reg_value << 8; 497 | index |= 0x80 | divisor; 498 | index |= (unsigned short)factor << 8; 499 | ch34x_vendor_write( VENDOR_SERIAL_INIT, value, index, serial, NULL, 0 ); 500 | 501 | // change control lines if we are switching to or from B0 502 | spin_lock_irqsave( &priv->lock, flags ); 503 | control = priv->line_control; 504 | if( (cflag & CBAUD) == B0 ) 505 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 506 | else 507 | priv->line_control |= (CONTROL_DTR | CONTROL_RTS); 508 | 509 | if( control != priv->line_control ) { 510 | control = priv->line_control; 511 | spin_unlock_irqrestore( &priv->lock, flags ); 512 | set_control_lines( serial, control ); 513 | } 514 | else 515 | spin_unlock_irqrestore( &priv->lock, flags ); 516 | 517 | if( cflag & CRTSCTS ) 518 | ch34x_vendor_write( VENDOR_WRITE, 0x2727, 0x0101, serial, NULL, 0); 519 | 520 | // FIXME: Need to read back resulting baud rate 521 | if( baud_rate ) 522 | tty_encode_baud_rate(tty, baud_rate, baud_rate); 523 | 524 | } 525 | 526 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,3)) 527 | static int ch34x_tiocmget( struct tty_struct *tty ) 528 | { 529 | struct usb_serial_port *port = tty->driver_data; 530 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 531 | static int ch34x_tiocmget( struct tty_struct *tty, 532 | struct file *filp ) 533 | { 534 | struct usb_serial_port *port = tty->driver_data; 535 | #else 536 | static int ch34x_tiocmget( struct usb_serial_port *port, 537 | struct file *filp ) 538 | { 539 | #endif 540 | struct ch34x_private *priv = usb_get_serial_port_data(port); 541 | unsigned long flags; 542 | unsigned int mcr; 543 | /*unsigned int msr;*/ 544 | unsigned int retval; 545 | 546 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 547 | dbg_ch34x("%s - port:%d", __func__, port->number); 548 | #else 549 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 550 | #endif 551 | if( !usb_get_intfdata( port->serial->interface) ) 552 | return -ENODEV; 553 | 554 | spin_lock_irqsave( &priv->lock, flags ); 555 | mcr = priv->line_control; 556 | spin_unlock_irqrestore( &priv->lock, flags ); 557 | 558 | retval = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) | 559 | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) | 560 | ((mcr & UART_CTS) ? TIOCM_CTS : 0) | 561 | ((mcr & UART_DSR) ? TIOCM_DSR : 0) | 562 | ((mcr & UART_RING) ? TIOCM_RI : 0) | 563 | ((mcr & UART_DCD) ? TIOCM_CD : 0); 564 | 565 | dbg_ch34x("%s - retval=0x%x", __func__, retval); 566 | 567 | return retval; 568 | } 569 | 570 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) && \ 571 | LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) ) 572 | static void ch34x_close( struct tty_struct *tty, 573 | struct usb_serial_port *port, struct file *filp ) 574 | { 575 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32) ) 576 | static void ch34x_close( struct usb_serial_port *port ) 577 | { 578 | struct tty_struct *tty = port->port.tty; 579 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) 580 | static void ch34x_close( struct usb_serial_port *port, 581 | struct file *filp ) 582 | { 583 | 584 | struct tty_struct *tty = port->tty; 585 | #endif 586 | struct ch34x_private *priv = usb_get_serial_port_data(port); 587 | unsigned long flags; 588 | unsigned int c_cflag; 589 | int bps; 590 | long timeout; 591 | wait_queue_t wait; 592 | 593 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 594 | dbg_ch34x("%s - port:%d", __func__, port->number); 595 | #else 596 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 597 | #endif 598 | // dbg_ch34x("Addr of priv: 0x%x", priv); 599 | // dbg_ch34x("Addr of tty: 0x%x", tty); 600 | // wait for data do drain from the buffer 601 | /* 602 | spin_lock_irqsave( &priv->lock, flags ); 603 | timeout = CH34x_CLOSING_WAIT; 604 | init_waitqueue_entry( &wait, current ); 605 | add_wait_queue( &tty->write_wait, &wait ); 606 | for(;;) { 607 | set_current_state( TASK_INTERRUPTIBLE ); 608 | if( ch34x_buf_data_avail(priv->buf) == 0 || timeout == 0 || 609 | signal_pending(current) || port->serial->disconnected ) 610 | break; 611 | spin_unlock_irqrestore( &priv->lock, flags ); 612 | timeout = schedule_timeout( timeout ); 613 | spin_lock_irqsave( &priv->lock, flags ); 614 | } 615 | set_current_state( TASK_RUNNING ); 616 | remove_wait_queue( &tty->write_wait, &wait ); 617 | */ 618 | spin_lock_irqsave( &priv->lock, flags ); 619 | // clear out any remaining data in the buffer 620 | ch34x_buf_clear( priv->buf ); 621 | spin_unlock_irqrestore( &priv->lock, flags ); 622 | 623 | /* 624 | bps = tty_get_baud_rate( tty ); 625 | if( bps > 1200 ) 626 | timeout = max( (HZ * 2560) / bps, HZ / 10 ); 627 | else 628 | timeout = 2 * HZ; 629 | schedule_timeout_interruptible(timeout); 630 | */ 631 | // shutdown our urbs 632 | usb_kill_urb(port->interrupt_in_urb); 633 | usb_kill_urb(port->read_urb); 634 | usb_kill_urb(port->write_urb); 635 | //usb_serial_generic_close(port, filp); 636 | 637 | if( tty ) { 638 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,1)) //sure 639 | c_cflag = tty->termios.c_cflag; 640 | #else 641 | c_cflag = tty->termios->c_cflag; 642 | #endif 643 | if( c_cflag & HUPCL ) { 644 | // drop DTR and RTS 645 | spin_lock_irqsave( &priv->lock, flags ); 646 | priv->line_control = 0; 647 | spin_unlock_irqrestore( &priv->lock, flags ); 648 | set_control_lines( port->serial, 0 ); 649 | } 650 | } 651 | 652 | // usb_serial_generic_close(port); 653 | // usb_kill_urb(port->interrupt_in_urb); 654 | 655 | } 656 | 657 | // kernel version 658 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) \ 659 | && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 660 | static int ch34x_open( struct tty_struct *tty, 661 | struct usb_serial_port *port, struct file *filp ) 662 | { 663 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) 664 | static int ch34x_open( struct tty_struct *tty, 665 | struct usb_serial_port *port ) 666 | { 667 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) 668 | static int ch34x_open( struct usb_serial_port *port, 669 | struct file *filp ) 670 | { 671 | struct tty_struct *tty = port->tty; 672 | #endif 673 | struct ktermios tmp_termios; 674 | struct usb_serial *serial = port->serial; 675 | int retval; 676 | 677 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 678 | dbg_ch34x("%s - port:%d", __func__, port->number ); 679 | #else 680 | dbg_ch34x("%s - port:%d", __func__, port->port_number ); 681 | #endif 682 | usb_clear_halt( serial->dev, port->write_urb->pipe ); 683 | usb_clear_halt( serial->dev, port->read_urb->pipe ); 684 | 685 | if( tty ) { 686 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 687 | ch34x_set_termios( tty, port, &tmp_termios ); 688 | #else 689 | ch34x_set_termios( port, &tmp_termios ); 690 | #endif 691 | } 692 | 693 | dbg_ch34x("%s - submit read urb", __func__); 694 | port->read_urb->dev = serial->dev; 695 | retval = usb_submit_urb( port->read_urb, GFP_KERNEL ); 696 | if(retval) { 697 | dev_err( &port->dev, "%s - failed submit read urb,error %d\n", 698 | __func__, retval ); 699 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) && \ 700 | LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) ) 701 | ch34x_close(tty, port, NULL); 702 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) 703 | ch34x_close(port); 704 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) 705 | ch34x_close(port, filp); 706 | #endif 707 | goto err_out; 708 | } 709 | 710 | dbg_ch34x("%s - submit interrupt urb", __func__ ); 711 | port->interrupt_in_urb->dev = serial->dev; 712 | retval = usb_submit_urb( port->interrupt_in_urb, GFP_KERNEL ); 713 | if(retval) { 714 | dev_err( &port->dev, "%s - failed submit interrupt urb,error %d\n", 715 | __func__, retval ); 716 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) && \ 717 | LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) ) 718 | ch34x_close(tty, port, NULL); 719 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) 720 | ch34x_close(port); 721 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) 722 | ch34x_close(port, filp); 723 | #endif 724 | goto err_out; 725 | } 726 | 727 | err_out: 728 | return retval; 729 | } 730 | 731 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,3)) 732 | static int ch34x_tiocmset( struct tty_struct *tty, 733 | unsigned int set, unsigned int clear ) 734 | { 735 | struct usb_serial_port *port = tty->driver_data; 736 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 737 | static int ch34x_tiocmset( struct tty_struct *tty, 738 | struct file *filp, unsigned int set, unsigned int clear ) 739 | { 740 | struct usb_serial_port *port = tty->driver_data; 741 | #else 742 | static int ch34x_tiocmset( struct usb_serial_port *port, 743 | struct file *filp, unsigned int set, unsigned int clear ) 744 | { 745 | #endif 746 | struct ch34x_private *priv = usb_get_serial_port_data(port); 747 | unsigned long flags; 748 | /*unsigned int mcr = priv->line_control;*/ 749 | u8 control; 750 | 751 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 752 | dbg_ch34x("%s - port:%d", __func__, port->number); 753 | #else 754 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 755 | #endif 756 | 757 | if( !usb_get_intfdata(port->serial->interface) ) 758 | return -ENODEV; 759 | 760 | spin_lock_irqsave( &priv->lock, flags ); 761 | if( set & TIOCM_RTS ) 762 | priv->line_control |= CONTROL_RTS; 763 | if( set & TIOCM_DTR ) 764 | priv->line_control |= CONTROL_DTR; 765 | if( clear & TIOCM_RTS ) 766 | priv->line_control &= ~CONTROL_RTS; 767 | if( clear & TIOCM_DTR ) 768 | priv->line_control &= ~CONTROL_DTR; 769 | control = priv->line_control; 770 | spin_unlock_irqrestore( &priv->lock, flags ); 771 | 772 | return set_control_lines( port->serial, control ); 773 | } 774 | 775 | static int wait_modem_info( struct usb_serial_port *port, 776 | unsigned int arg ) 777 | { 778 | struct ch34x_private *priv = usb_get_serial_port_data(port); 779 | unsigned long flags; 780 | unsigned int prevstatus; 781 | unsigned int status; 782 | unsigned int changed; 783 | 784 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 785 | dbg_ch34x("%s -port:%d", __func__, port->number); 786 | #else 787 | dbg_ch34x("%s -port:%d", __func__, port->port_number); 788 | #endif 789 | spin_lock_irqsave( &priv->lock, flags ); 790 | prevstatus = priv->line_status; 791 | spin_unlock_irqrestore( &priv->lock, flags ); 792 | 793 | while(1) { 794 | wait_event_interruptible( wq, wait_flag != 0 ); 795 | wait_flag = 0; 796 | // see if a signal did it 797 | if( signal_pending(current) ) 798 | return -ERESTARTSYS; 799 | 800 | spin_lock_irqsave( &priv->lock, flags ); 801 | status = priv->line_status; 802 | spin_unlock_irqrestore( &priv->lock, flags ); 803 | 804 | changed = prevstatus ^ status; 805 | 806 | if( ((arg & TIOCM_RNG) && (changed & UART_RING)) || 807 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || 808 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || 809 | ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) 810 | return 0; 811 | 812 | prevstatus = status; 813 | } 814 | 815 | // Not reatched 816 | return 0; 817 | } 818 | 819 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,3)) 820 | static int ch34x_ioctl( struct tty_struct *tty, 821 | unsigned int cmd, unsigned long arg ) 822 | { 823 | struct usb_serial_port *port = tty->driver_data; 824 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 825 | static int ch34x_ioctl( struct tty_struct *tty, 826 | struct file *filp, unsigned int cmd, unsigned long arg ) 827 | { 828 | struct usb_serial_port *port = tty->driver_data; 829 | #else 830 | static int ch34x_ioctl( struct usb_serial_port *port, 831 | struct file *filp, unsigned int cmd, unsigned long arg ) 832 | { 833 | //struct usb_serial_port *port = tty->driver_data; 834 | #endif 835 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 836 | dbg_ch34x("%s - port:%d, cmd=0x%04x", __func__, port->number, cmd); 837 | #else 838 | dbg_ch34x("%s - port:%d, cmd=0x%04x", __func__, port->port_number, cmd); 839 | #endif 840 | switch(cmd) 841 | { 842 | // Note here 843 | case TIOCMIWAIT: 844 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 845 | dbg_ch34x("%s - port:%d TIOCMIWAIT", __func__, port->number); 846 | #else 847 | dbg_ch34x("%s - port:%d TIOCMIWAIT", __func__, port->port_number); 848 | #endif 849 | 850 | return wait_modem_info(port, arg); 851 | default: 852 | dbg_ch34x("%s not supported=0x%04x", __func__, cmd); 853 | break; 854 | } 855 | 856 | return -ENOIOCTLCMD; 857 | } 858 | 859 | static void ch34x_send( struct usb_serial_port *port ) 860 | { 861 | int count; 862 | int retval; 863 | struct ch34x_private *priv = usb_get_serial_port_data( port ); 864 | unsigned long flags; 865 | 866 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 867 | dbg_ch34x("%s - port:%d", __func__, port->number); 868 | #else 869 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 870 | #endif 871 | spin_lock_irqsave( &priv->lock, flags ); 872 | if( priv->write_urb_in_use ) { 873 | spin_unlock_irqrestore( &priv->lock, flags ); 874 | return; 875 | } 876 | 877 | count = ch34x_buf_get( priv->buf, port->write_urb->transfer_buffer, 878 | port->bulk_out_size ); 879 | if( count == 0 ) { 880 | spin_unlock_irqrestore( &priv->lock, flags ); 881 | return; 882 | } 883 | 884 | priv->write_urb_in_use = 1; 885 | spin_unlock_irqrestore( &priv->lock, flags ); 886 | 887 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,1)) 888 | usb_serial_debug_data( &port->dev, __func__, count, 889 | port->write_urb->transfer_buffer ); 890 | #else 891 | usb_serial_debug_data( debug, &port->dev, __func__, count, 892 | port->write_urb->transfer_buffer ); 893 | #endif 894 | 895 | port->write_urb->transfer_buffer_length = count; 896 | port->write_urb->dev = port->serial->dev; 897 | retval = usb_submit_urb( port->write_urb, GFP_ATOMIC ); 898 | if( retval ) { 899 | dev_err( &port->dev, "%s - failed submitting write urb,error %d\n" 900 | , __func__, retval ); 901 | priv->write_urb_in_use = 0; 902 | // reschedule ch34x_send 903 | } 904 | 905 | usb_serial_port_softint( port ); 906 | } 907 | 908 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 909 | static int ch34x_write( struct tty_struct *tty, 910 | struct usb_serial_port *port, const unsigned char *buf, int count ) 911 | #else 912 | static int ch34x_write( struct usb_serial_port *port, 913 | const unsigned char *buf, int count ) 914 | #endif 915 | { 916 | struct ch34x_private *priv = usb_get_serial_port_data(port); 917 | unsigned long flags; 918 | 919 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 920 | dbg_ch34x("%s - port:%d, %d bytes", __func__, port->number, count); 921 | #else 922 | dbg_ch34x("%s - port:%d, %d bytes", __func__, port->port_number, count); 923 | #endif 924 | 925 | if( !count ) 926 | return count; 927 | 928 | spin_lock_irqsave( &priv->lock, flags ); 929 | count = ch34x_buf_put( priv->buf, buf, count ); 930 | spin_unlock_irqrestore( &priv->lock, flags ); 931 | 932 | ch34x_send(port); 933 | 934 | return count; 935 | } 936 | 937 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 938 | static int ch34x_write_room( struct tty_struct *tty ) 939 | { 940 | struct usb_serial_port *port = tty->driver_data; 941 | #else 942 | static int ch34x_write_room( struct usb_serial_port *port ) 943 | { 944 | #endif 945 | struct ch34x_private *priv = usb_get_serial_port_data( port ); 946 | int room = 0; 947 | unsigned long flags; 948 | 949 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 950 | dbg_ch34x("%s - port:%d", __func__, port->number); 951 | #else 952 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 953 | #endif 954 | 955 | spin_lock_irqsave( &priv->lock, flags ); 956 | room = ch34x_buf_space_avail( priv->buf ); 957 | spin_unlock_irqrestore( &priv->lock, flags ); 958 | 959 | dbg_ch34x("%s - room:%d", __func__, room ); 960 | return room; 961 | } 962 | 963 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 964 | static int ch34x_chars_in_buffer( struct tty_struct *tty ) 965 | { 966 | struct usb_serial_port *port = tty->driver_data; 967 | #else 968 | static int ch34x_chars_in_buffer( struct usb_serial_port *port ) 969 | { 970 | #endif 971 | struct ch34x_private *priv = usb_get_serial_port_data(port); 972 | int chars = 0; 973 | unsigned long flags; 974 | 975 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 976 | dbg_ch34x("%s - port:%d", __func__, port->number); 977 | #else 978 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 979 | #endif 980 | 981 | spin_lock_irqsave( &priv->lock, flags ); 982 | chars = ch34x_buf_data_avail( priv->buf ); 983 | spin_unlock_irqrestore( &priv->lock, flags ); 984 | 985 | dbg_ch34x("%s - chars:%d", __func__, chars ); 986 | 987 | return chars; 988 | } 989 | 990 | static int ch34x_attach( struct usb_serial *serial ) 991 | { 992 | struct ch34x_private *priv; 993 | int i; 994 | char buf[8]; 995 | 996 | dbg_ch34x("%s", __func__); 997 | 998 | for( i = 0; i < serial->num_ports; ++i ) { 999 | priv = kzalloc( sizeof(struct ch34x_private), GFP_KERNEL ); 1000 | if( !priv ) 1001 | goto cleanup; 1002 | spin_lock_init( &priv->lock ); 1003 | priv->buf = ch34x_buf_alloc( CH34x_BUF_SIZE ); 1004 | if( priv->buf == NULL ) { 1005 | kfree( priv ); 1006 | goto cleanup; 1007 | } 1008 | init_waitqueue_head( &priv->delta_msr_wait ); 1009 | usb_set_serial_port_data( serial->port[i], priv ); 1010 | } 1011 | 1012 | ch34x_vendor_read( VENDOR_VERSION, 0x0000, 0x0000, 1013 | serial, buf, 0x02 ); 1014 | ch34x_vendor_write( VENDOR_SERIAL_INIT, 0x0000, 0x0000, 1015 | serial, NULL, 0x00 ); 1016 | ch34x_vendor_write( VENDOR_WRITE, 0x1312, 0xD982, 1017 | serial, NULL, 0x00 ); 1018 | ch34x_vendor_write( VENDOR_WRITE, 0x0F2C, 0x0004, 1019 | serial, NULL, 0x00 ); 1020 | ch34x_vendor_read( VENDOR_READ, 0x2518, 0x0000, 1021 | serial, buf, 0x02 ); 1022 | ch34x_vendor_write( VENDOR_WRITE, 0x2727, 0x0000, 1023 | serial, NULL, 0x00 ); 1024 | ch34x_vendor_write( VENDOR_MODEM_OUT, 0x009F, 0x0000, 1025 | serial, NULL, 0x00 ); 1026 | 1027 | return 0; 1028 | 1029 | cleanup: 1030 | for( --i; i >= 0; --i ) { 1031 | priv = usb_get_serial_port_data( serial->port[i] ); 1032 | ch34x_buf_free( priv->buf ); 1033 | kfree( priv ); 1034 | usb_set_serial_port_data( serial->port[i], NULL ); 1035 | } 1036 | 1037 | return -ENOMEM; 1038 | } 1039 | 1040 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)) 1041 | static void ch34x_shutdown( struct usb_serial *serial ) 1042 | { 1043 | struct ch34x_private *priv; 1044 | int i; 1045 | 1046 | dbg_ch34x("%s", __func__); 1047 | 1048 | for( i = 0; i < serial->num_ports; ++i ) { 1049 | priv = usb_get_serial_port_data( serial->port[i] ); 1050 | if( priv ) { 1051 | ch34x_buf_free( priv->buf ); 1052 | kfree( priv ); 1053 | usb_set_serial_port_data( serial->port[i], NULL ); 1054 | } 1055 | } 1056 | } 1057 | #endif 1058 | 1059 | static void ch34x_update_line_status( struct usb_serial_port *port, 1060 | unsigned char *data, unsigned int actual_length ) 1061 | { 1062 | struct ch34x_private *priv = usb_get_serial_port_data( port ); 1063 | unsigned long flags; 1064 | u8 length = UART_STATE + 0x04; 1065 | 1066 | if( actual_length < length ) 1067 | return; 1068 | 1069 | // Save off the uart status for others to look at 1070 | spin_lock_irqsave( &priv->lock, flags ); 1071 | priv->line_status = data[UART_STATE]; 1072 | priv->line_control = data[PORTB_STATE]; 1073 | spin_unlock_irqrestore( &priv->lock, flags ); 1074 | wait_flag = 1; 1075 | wake_up_interruptible( &priv->delta_msr_wait ); 1076 | } 1077 | 1078 | static void ch34x_read_int_callback( struct urb *urb ) 1079 | { 1080 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1081 | unsigned char *data = urb->transfer_buffer; 1082 | unsigned int actual_length = urb->actual_length; 1083 | int status = urb->status; 1084 | int retval; 1085 | 1086 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 1087 | dbg_ch34x("%s port:%d", __func__, port->number ); 1088 | #else 1089 | dbg_ch34x("%s port:%d", __func__, port->port_number ); 1090 | #endif 1091 | switch( status ) { 1092 | case 0: //success 1093 | break; 1094 | case -ECONNRESET: 1095 | case -ENOENT: 1096 | case -ESHUTDOWN: //this urb is terminated, clean up 1097 | dbg_ch34x("%s - urb shutting down with status:%d", __func__, status ); 1098 | return; 1099 | default: 1100 | dbg_ch34x("%s - nonzero urb status received:%d", __func__, status ); 1101 | goto exit; 1102 | } 1103 | 1104 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,1)) 1105 | usb_serial_debug_data( &port->dev, __func__, 1106 | urb->actual_length, urb->transfer_buffer ); 1107 | #else 1108 | usb_serial_debug_data( debug, &port->dev, 1109 | __func__, urb->actual_length, urb->transfer_buffer ); 1110 | #endif 1111 | 1112 | ch34x_update_line_status( port, data, actual_length ); 1113 | 1114 | exit: 1115 | retval = usb_submit_urb( urb, GFP_ATOMIC ); 1116 | if( retval ) 1117 | dev_err( &urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1118 | __func__, retval ); 1119 | } 1120 | 1121 | static void ch34x_read_bulk_callback( struct urb *urb ) 1122 | { 1123 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1124 | struct ch34x_private *priv = usb_get_serial_port_data( port ); 1125 | struct tty_struct *tty; 1126 | unsigned char *data = urb->transfer_buffer; 1127 | unsigned long flags; 1128 | int i; 1129 | int retval; 1130 | int status = urb->status; 1131 | u8 line_status; 1132 | char tty_flag; 1133 | 1134 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 1135 | dbg_ch34x("%s - port:%d", __func__, port->number ); 1136 | #else 1137 | dbg_ch34x("%s - port:%d", __func__, port->port_number); 1138 | #endif 1139 | if( status ) { 1140 | dbg_ch34x("%s - urb status=%d", __func__, status ); 1141 | if( status == -EPROTO ) { 1142 | // CH34x mysteriously fails with -EPROTO reschedule the read 1143 | dbg_ch34x("%s - caught -EPROTO, resubmitting the urb", __func__); 1144 | urb->dev = port->serial->dev; 1145 | retval = usb_submit_urb( urb, GFP_ATOMIC ); 1146 | if( retval ) { 1147 | dev_err( &urb->dev->dev, 1148 | "%s - failed resubmitting read urb, error %d\n", 1149 | __func__, retval ); 1150 | return; 1151 | } 1152 | } 1153 | 1154 | dbg_ch34x("%s - unable to handle the error, exiting.", __func__); 1155 | return; 1156 | } 1157 | 1158 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,1)) 1159 | usb_serial_debug_data( &port->dev, __func__, 1160 | urb->actual_length, data ); 1161 | #else 1162 | usb_serial_debug_data( debug, &port->dev, 1163 | __func__, urb->actual_length, data ); 1164 | #endif 1165 | 1166 | // get tty_flag from status 1167 | tty_flag = TTY_NORMAL; 1168 | 1169 | spin_lock_irqsave( &priv->lock, flags ); 1170 | line_status = priv->line_status; 1171 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 1172 | spin_unlock_irqrestore( &priv->lock, flags ); 1173 | wait_flag = 1; 1174 | wake_up_interruptible( &priv->delta_msr_wait ); 1175 | 1176 | // break takes precedence over parity, 1177 | // which takes precedence over framing errors 1178 | if( line_status & UART_PARITY_ERROR ) 1179 | tty_flag = TTY_PARITY; 1180 | else if( line_status & UART_OVERRUN_ERROR ) 1181 | tty_flag = TTY_OVERRUN; 1182 | else if( line_status & UART_FRAME_ERROR ) 1183 | tty_flag = TTY_FRAME; 1184 | dbg_ch34x("%s - tty_flag=%d", __func__, tty_flag); 1185 | 1186 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) 1187 | tty = port->port.tty; 1188 | #else 1189 | tty = port->tty; 1190 | #endif 1191 | if( tty && urb->actual_length ) { 1192 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,1)) 1193 | tty_buffer_request_room( tty->port, urb->actual_length + 1); 1194 | #else 1195 | tty_buffer_request_room( tty, urb->actual_length + 1 ); 1196 | #endif 1197 | // overrun is special, not associated with a char 1198 | if( line_status & UART_OVERRUN_ERROR ) 1199 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,1)) 1200 | tty_insert_flip_char( tty->port, 0, TTY_OVERRUN ); 1201 | #else 1202 | tty_insert_flip_char( tty, 0, TTY_OVERRUN ); 1203 | #endif 1204 | for( i = 0; i < urb->actual_length; ++i ) 1205 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,1)) 1206 | tty_insert_flip_char( tty->port, data[i], tty_flag ); 1207 | #else 1208 | tty_insert_flip_char( tty, data[i], tty_flag ); 1209 | #endif 1210 | 1211 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,1)) 1212 | tty_flip_buffer_push( tty->port ); 1213 | #else 1214 | tty_flip_buffer_push( tty ); 1215 | #endif 1216 | } 1217 | 1218 | //Schedule the next read _if_ we are still open 1219 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) 1220 | if( port->open_count ) 1221 | #endif 1222 | { 1223 | urb->dev = port->serial->dev; 1224 | retval = usb_submit_urb( urb, GFP_ATOMIC ); 1225 | if( retval ) 1226 | dev_err( &urb->dev->dev, 1227 | "%s - fialed resubmitting read urb, error %d\n", 1228 | __func__, retval ); 1229 | } 1230 | 1231 | return; 1232 | } 1233 | 1234 | static void ch34x_write_bulk_callback( struct urb *urb ) 1235 | { 1236 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1237 | struct ch34x_private *priv = usb_get_serial_port_data(port); 1238 | int retval; 1239 | int status = urb->status; 1240 | 1241 | #if(LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)) 1242 | dbg_ch34x("%s - port:%d", __func__, port->number ); 1243 | #else 1244 | dbg_ch34x("%s - port:%d", __func__, port->port_number ); 1245 | #endif 1246 | switch( status ) { 1247 | case 0: //success 1248 | break; 1249 | case -ECONNRESET: 1250 | case -ENOENT: 1251 | case -ESHUTDOWN: 1252 | // this urb is terminated, clean up 1253 | dbg_ch34x("%s - urb shutting down with status:%d", __func__, status); 1254 | priv->write_urb_in_use = 0; 1255 | return; 1256 | default: 1257 | // error in the urb, so we have to resubmit it 1258 | dbg_ch34x("%s - Overflow in write", __func__); 1259 | dbg_ch34x("%s - nonzero write bulk status received:%d", __func__, status); 1260 | port->write_urb->transfer_buffer_length = 1; 1261 | port->write_urb->dev = port->serial->dev; 1262 | retval = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1263 | if( retval ) 1264 | dev_err( &urb->dev->dev, 1265 | "%s - failed resubmitting write urv, error:%d\n", 1266 | __func__, retval ); 1267 | else 1268 | return; 1269 | } 1270 | 1271 | priv->write_urb_in_use = 0; 1272 | 1273 | // send any buffered data 1274 | ch34x_send(port); 1275 | } 1276 | 1277 | static struct usb_serial_driver ch34x_device = { 1278 | .driver = { 1279 | .owner = THIS_MODULE, 1280 | .name = "ch34x", 1281 | }, 1282 | .id_table = id_table, 1283 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,1)) 1284 | .usb_driver = &ch34x_driver, 1285 | #endif 1286 | .num_ports = 1, 1287 | .open = ch34x_open, 1288 | .close = ch34x_close, 1289 | .write = ch34x_write, 1290 | .ioctl = ch34x_ioctl, 1291 | .set_termios = ch34x_set_termios, 1292 | .tiocmget = ch34x_tiocmget, 1293 | .tiocmset = ch34x_tiocmset, 1294 | .read_bulk_callback = ch34x_read_bulk_callback, 1295 | .read_int_callback = ch34x_read_int_callback, 1296 | .write_bulk_callback = ch34x_write_bulk_callback, 1297 | .write_room = ch34x_write_room, 1298 | .chars_in_buffer = ch34x_chars_in_buffer, 1299 | .attach = ch34x_attach, 1300 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) ) 1301 | .shutdown = ch34x_shutdown, 1302 | #endif 1303 | }; 1304 | 1305 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,5)) 1306 | static struct usb_serial_driver *const serial_driver [] = { 1307 | &ch34x_device, NULL 1308 | }; 1309 | #endif 1310 | 1311 | 1312 | static int __init ch34x_init(void) 1313 | { 1314 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5)) 1315 | int retval = 0; 1316 | 1317 | retval = usb_serial_register( &ch34x_device ); 1318 | if( retval ) { 1319 | goto err_usb_serial_register; 1320 | } 1321 | retval = usb_register( &ch34x_driver ); 1322 | if( retval ) { 1323 | goto err_usb_register; 1324 | } 1325 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)) 1326 | info( DRIVER_DESC ); 1327 | #endif 1328 | return 0; 1329 | 1330 | err_usb_register: 1331 | usb_deregister( &ch34x_driver ); 1332 | err_usb_serial_register: 1333 | usb_serial_deregister( &ch34x_device ); 1334 | return retval; 1335 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,1)) 1336 | return usb_serial_register_drivers( serial_driver, 1337 | KBUILD_MODNAME, id_table ); 1338 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,5) && \ 1339 | LINUX_VERSION_CODE < KERNEL_VERSION(3,5,1)) 1340 | return usb_serial_register_drivers(&ch34x_driver, serial_driver); 1341 | #endif 1342 | } 1343 | 1344 | static void __exit ch34x_exit(void) 1345 | { 1346 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,5)) 1347 | usb_deregister( &ch34x_driver ); 1348 | usb_serial_deregister( &ch34x_device ); 1349 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,1)) 1350 | usb_serial_deregister_drivers( serial_driver ); 1351 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,5) && \ 1352 | LINUX_VERSION_CODE < KERNEL_VERSION(3,5,1)) 1353 | usb_serial_deregister_drivers(&ch34x_driver, serial_driver); 1354 | #endif 1355 | } 1356 | 1357 | module_init( ch34x_init ); 1358 | module_exit( ch34x_exit ); 1359 | 1360 | 1361 | MODULE_DESCRIPTION(DRIVER_DESC); 1362 | MODULE_AUTHOR(DRIVER_AUTHOR); 1363 | MODULE_LICENSE("GPL"); 1364 | -------------------------------------------------------------------------------- /CH341SER_LINUX/CH341SER_LINUX/readme.txt: -------------------------------------------------------------------------------- 1 | // ChangeLog 2 | // 1.0 - 1.1 modified to solve transmition between ch341 and ch341 3 | // 1.1 - 1.2 Support high Linux kernel 4 | Instructions 5 | 6 | Note: 1.Please run followed executable programs as root privilege 7 | 2.Current Driver support versions of linux kernel range from 2.6.25 to 3.13.x 8 | 3.Current Driver support 32bits and 64bits linux systems 9 | 10 | Usage: 11 | (load or unload linux driver of CH34x) 12 | //compile 13 | #make 14 | //load ch34x chips driver 15 | #make load 16 | //unload ch34x chips driver 17 | #make unload 18 | // 1.2 - 1.3 Fix some bugs 19 | 20 | -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341PT.DLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341PT.DLL -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341S64.SYS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341S64.SYS -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341S98.SYS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341S98.SYS -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341SER.INF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341SER.INF -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341SER.SYS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341SER.SYS -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/CH341SER.VXD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/CH341SER.VXD -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/DRVSETUP64/DRVSETUP64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/DRVSETUP64/DRVSETUP64.exe -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/SETUP.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/SETUP.EXE -------------------------------------------------------------------------------- /CH341SER_for_64bit_win7/CH341SER/ch341SER.CAT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH341SER_for_64bit_win7/CH341SER/ch341SER.CAT -------------------------------------------------------------------------------- /CH34XUSB-SERIAL_for_mac/CH34x_Install_V1.3.pkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH34XUSB-SERIAL_for_mac/CH34x_Install_V1.3.pkg -------------------------------------------------------------------------------- /CH34XUSB-SERIAL_for_mac/Readme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/CH34XUSB-SERIAL_for_mac/Readme.pdf -------------------------------------------------------------------------------- /How to start.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/How to start.pdf -------------------------------------------------------------------------------- /Lesson1-LED Running Lights/LED Running Lights.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson1-LED Running Lights/LED Running Lights.pdf -------------------------------------------------------------------------------- /Lesson1-LED Running Lights/LED_Running_Lights/LED_Running_Lights.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [object] LED_Running_Lights 26 | * [diagram] 27 | * PIN 2 ================== LED0 ( left ) 28 | * PIN 3 ================== LED1 29 | * PIN 4 ================== LED2 30 | * PIN 5 ================== LED3 31 | * PIN 6 ================== LED4 32 | * PIN 7 ================== LED5 33 | * PIN 8 ================== LED6 34 | * PIN 9 ================== LED7 ( right ) 35 | */ 36 | 37 | int led_array[8] = {2, 3, 4, 5, 6, 7, 8 , 9 }; 38 | int flash_speed = 500; 39 | 40 | /* flash led form left to right one by one */ 41 | void led_flash(void) 42 | { 43 | int i; 44 | for(i = 0; i < 8; i++ ) 45 | { 46 | digitalWrite(led_array[i],LOW); 47 | delay(flash_speed); 48 | digitalWrite(led_array[i],HIGH); 49 | } 50 | } 51 | 52 | /* turn on all led form left to right */ 53 | void led_turn_on(void) 54 | { 55 | int i; 56 | for (i = 0; i < 8; i++ ) 57 | { 58 | digitalWrite(led_array[i],LOW); 59 | delay(flash_speed); 60 | } 61 | } 62 | 63 | /* turn off all led */ 64 | void led_turn_off(void) 65 | { 66 | int i; 67 | for (i = 0; i < 8; i++ ) { 68 | digitalWrite(led_array[i],HIGH); 69 | delay(flash_speed); 70 | } 71 | } 72 | void setup() 73 | { 74 | // put your setup code here, to run once: 75 | int i; 76 | Serial.begin(115200); 77 | for (i = 0; i < 8; i++ ) { 78 | pinMode(led_array[i],OUTPUT); 79 | digitalWrite(led_array[i],HIGH); // set led control pin defalut HIGH turn off all LED 80 | } 81 | } 82 | 83 | void loop() 84 | { 85 | // put your main code here, to run repeatedly: 86 | Serial.println("start flash led !"); 87 | led_flash(); 88 | led_turn_on(); 89 | led_turn_off(); 90 | 91 | } 92 | -------------------------------------------------------------------------------- /Lesson10-LM35Temperature Sensor/LM35/LM35.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] 26 | * [Diagram] 27 | 28 | */ 29 | int Temp_Pin = A0; // analog pin line LM35 numble 2 wire 30 | int val; 31 | int dat; 32 | float voltage = 0.0 ; 33 | void setup() 34 | { 35 | Serial.begin(115200); //init serial Baud rate 115200 36 | } 37 | void loop() 38 | { 39 | val = analogRead(Temp_Pin); // read analog raw data 40 | voltage = ( ( float )val )/1023; 41 | voltage = voltage * 5 ; // convert analog value to real voltage 42 | dat = voltage * 100; // convert voltage to temprature 43 | Serial.print("Current Temp : "); 44 | Serial.print(dat); 45 | Serial.println("C"); 46 | delay(500); // Delay 0.5 s 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Lesson10-LM35Temperature Sensor/LM35Temperature Sensor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson10-LM35Temperature Sensor/LM35Temperature Sensor.pdf -------------------------------------------------------------------------------- /Lesson10-LM35Temperature Sensor/LM35_datasheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson10-LM35Temperature Sensor/LM35_datasheet.pdf -------------------------------------------------------------------------------- /Lesson11-L293D for a DC Motor/L293D for a DC Motor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson11-L293D for a DC Motor/L293D for a DC Motor.pdf -------------------------------------------------------------------------------- /Lesson11-L293D for a DC Motor/L293D-DataSheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson11-L293D for a DC Motor/L293D-DataSheet.pdf -------------------------------------------------------------------------------- /Lesson11-L293D for a DC Motor/motor/motor.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] L293D for a DC Motor 26 | * [Diagram] 27 | * L293D PIN 1 =================== Arduino PIN 3 28 | * L293D PIN 2 =================== Arduino PIN 5 29 | * L293D PIN 4 =================== Arduino PIN GND 30 | * L293D PIN 5 =================== Arduino PIN GND 31 | * L293D PIN 7 =================== Arduino PIN 4 32 | * L293D PIN 8 =================== Arduino PIN +5V 33 | * DC MOTOR +5V =================== 4N35 PIN 2 34 | * DC MOTOR GND =================== 4N35 PIN 5 35 | * L293D PIN 5 =================== 4N35 PIN 1 36 | * L293D PIN 5 =================== 4N35 PIN 4 37 | */ 38 | #define ENABLE 3 39 | #define DIRB 4 40 | #define DIRA 5 41 | 42 | int i; 43 | 44 | void setup() 45 | { 46 | //---set pin direction 47 | pinMode(ENABLE,OUTPUT); 48 | pinMode(DIRA,OUTPUT); 49 | pinMode(DIRB,OUTPUT); 50 | Serial.begin(9600); 51 | 52 | } 53 | 54 | void loop() 55 | { 56 | //---back and forth example 57 | Serial.println("One way, then reverse"); 58 | digitalWrite(ENABLE,HIGH); // enable on 59 | for (i=0;i<5;i++) 60 | { 61 | digitalWrite(DIRA,HIGH); //one way 62 | digitalWrite(DIRB,LOW); 63 | delay(500); 64 | digitalWrite(DIRA,LOW); //reverse 65 | digitalWrite(DIRB,HIGH); 66 | delay(500); 67 | } 68 | digitalWrite(ENABLE,LOW); // disable 69 | delay(4000); 70 | 71 | Serial.println("fast Slow example"); 72 | //---fast/slow stop example 73 | digitalWrite(ENABLE,HIGH); //enable on 74 | digitalWrite(DIRA,HIGH); //one way 75 | digitalWrite(DIRB,LOW); 76 | delay(1000); 77 | digitalWrite(ENABLE,LOW); //slow stop 78 | delay(3000); 79 | digitalWrite(ENABLE,HIGH); //enable on 80 | digitalWrite(DIRA,HIGH); //one way 81 | digitalWrite(DIRB,LOW); 82 | delay(1000); 83 | digitalWrite(DIRA,LOW); //fast stop 84 | delay(3000); 85 | 86 | //Serial.println("PWM full then slow"); 87 | //---PWM example, full speed then slow 88 | digitalWrite(ENABLE,HIGH); //enable on 89 | digitalWrite(DIRA,HIGH); //one way 90 | digitalWrite(DIRB,LOW); 91 | delay(2000); 92 | analogWrite(ENABLE,128); //half speed 93 | delay(2000); 94 | digitalWrite(ENABLE,LOW); //all done 95 | delay(10000); 96 | } 97 | -------------------------------------------------------------------------------- /Lesson12-Servo Motor/Servo Motor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson12-Servo Motor/Servo Motor.pdf -------------------------------------------------------------------------------- /Lesson12-Servo Motor/Servo/Servo.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] 26 | * [Diagram] 27 | 28 | */ 29 | int readPin = A0; 30 | int servopin = 7; 31 | 32 | void servopulse(int angle) 33 | { 34 | int pulsewidth=(angle*11)+500; 35 | digitalWrite(servopin,HIGH); 36 | delayMicroseconds(pulsewidth); 37 | digitalWrite(servopin,LOW); 38 | delayMicroseconds(20000-pulsewidth); 39 | } 40 | 41 | void setup() 42 | { 43 | pinMode(servopin,OUTPUT); 44 | } 45 | 46 | void loop() 47 | { 48 | int readValue = analogRead(readPin); 49 | int angle = readValue / 4; 50 | for(int i=0;i<50;i++) 51 | { 52 | servopulse(angle); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Lesson2-Photosensitive Resistorr/Photosensitive Light Experiment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson2-Photosensitive Resistorr/Photosensitive Light Experiment.pdf -------------------------------------------------------------------------------- /Lesson2-Photosensitive Resistorr/photosensitive/photosensitive.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | 24 | 25 | [Title] Photosensitive Light Experiment 26 | [diagram] 27 | 220Ω =================== LED 28 | 10kΩ =================== Photovaristor 29 | 30 | */ 31 | int photocellPin = 2; // photocell to anallog pin 2 32 | int photocellVal = 0; // photocell variable 33 | int minLight = 200; 34 | int ledPin = 12; 35 | int ledState = 0; 36 | 37 | void setup() 38 | { 39 | pinMode(ledPin, OUTPUT); 40 | Serial.begin(9600); 41 | } 42 | 43 | void loop() 44 | { 45 | photocellVal = analogRead(photocellPin); 46 | Serial.println(photocellVal); 47 | 48 | if (photocellVal < minLight && ledState == 0) 49 | { 50 | digitalWrite(ledPin, HIGH); // turn on LED 51 | ledState = 1; 52 | } 53 | 54 | if (photocellVal > minLight && ledState == 1) 55 | { 56 | digitalWrite(ledPin, LOW); // turn off LED 57 | ledState = 0; 58 | } 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /Lesson3-Button/Button.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson3-Button/Button.pdf -------------------------------------------------------------------------------- /Lesson3-Button/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] keypad control led light 26 | * [diagram] 27 | * Arduino PIN 11 =================== led control gpio 28 | * Arduino PIN 7 =================== keypad pin 29 | */ 30 | int led_out = 11 ; //GPIO 11 LED pin 31 | int keypad_pin = 7; //GPIO 7 key pin 32 | int value; 33 | void setup() 34 | { 35 | pinMode(led_out,OUTPUT); // init led pin output 36 | pinMode(keypad_pin,INPUT); // init key pin input 37 | } 38 | void loop() 39 | { 40 | value = digitalRead(keypad_pin); // read key pad pin vaule 41 | if( value == LOW ) 42 | { 43 | digitalWrite(led_out,LOW); // if key value is down turn off LED 44 | } 45 | else 46 | { 47 | digitalWrite(led_out,HIGH); // if key value is down turn on LED 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Lesson4-PWM/PWM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson4-PWM/PWM.pdf -------------------------------------------------------------------------------- /Lesson4-PWM/pwm/pwm.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] 26 | * [Diagram] 27 | 28 | */ 29 | int ADPIN = A0 ; 30 | int PWM_LEDPIN = 10 ; 31 | int value = 0 ; 32 | float voltage = 0.0 ; 33 | void setup() 34 | { 35 | pinMode(ADPIN, INPUT); // define ADPIN input PWM_LEDPIN output 36 | pinMode(PWM_LEDPIN, OUTPUT); 37 | Serial.begin(115200); //Serial Baud rate is 115200 38 | } 39 | void loop() 40 | { 41 | value = analogRead(ADPIN); //read analog pin raw data 42 | //voltage = ( ( float )value )/1023 ; 43 | //value = (int)voltage * 256 ; //covert to voltage to PWM duty cycle 44 | analogWrite(PWM_LEDPIN, value); 45 | delay(1000); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Lesson5-RGB breathing light/RGB LED.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson5-RGB breathing light/RGB LED.pdf -------------------------------------------------------------------------------- /Lesson5-RGB breathing light/RGB/RGB.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * [Title]: RGB breathing light 25 | * [Diagram] 26 | * Arduino PIN 11 =================== RGB pin1 red 27 | * Arduino PIN 10 =================== RGB pin3 green 28 | * Arduino PIN 9 =================== RGB pin4 blue 29 | * Arduino GND =================== RGB pin2 GND 30 | */ 31 | 32 | int led1 = 9; 33 | int led2 = 10; 34 | int led3 = 11; 35 | void setup() 36 | { 37 | pinMode(led1,OUTPUT); 38 | pinMode(led2,OUTPUT); 39 | pinMode(led3,OUTPUT); 40 | } 41 | void setColor(int red,int green,int blue) 42 | { 43 | analogWrite(led1,255-red); 44 | analogWrite(led2,255-green); 45 | analogWrite(led3,255-blue); 46 | } 47 | void loop() 48 | { 49 | int i,j,k; 50 | for(i=0,j=255;i<256;i++) 51 | { 52 | setColor(i,j,0); 53 | delay(4); 54 | j--; 55 | } 56 | delay(100); //green to res 57 | for(i=0,j=255;i<256;i++) 58 | { 59 | setColor(j,0,i); 60 | delay(4); 61 | j--; 62 | } 63 | delay(100); //red to blue 64 | for(i=0,j=255;i<256;i++) 65 | { 66 | setColor(0,i,j); 67 | delay(4); 68 | j--; 69 | } 70 | delay(100); //blue to green 71 | for(i=0,j=255;i<256;i++) 72 | { 73 | setColor(i,0,j); 74 | delay(4); 75 | j--; 76 | } 77 | delay(100); 78 | for(i=0,j=255;i<256;i++) 79 | { 80 | setColor(0,j,i); 81 | delay(4); 82 | j--; 83 | } 84 | delay(100); 85 | for(i=0,j=255;i<256;i++) 86 | { 87 | setColor(j,0,i); 88 | delay(4); 89 | j--; 90 | } 91 | delay(100); 92 | for(k=0;k<3;k++) 93 | { 94 | analogWrite(led1,255); 95 | analogWrite(led2,255); 96 | analogWrite(led3,255); 97 | delay(200); 98 | analogWrite(led1,0); 99 | analogWrite(led2,0); 100 | analogWrite(led3,0); 101 | delay(200); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Lesson5-RGB breathing light/RGB_Breathing_Light/RGB_Breathing_Light.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title]: RGB breathing light 26 | * [Diagram] 27 | * Arduino PIN 11 =================== RGB pin1 red 28 | * Arduino PIN 10 =================== RGB pin3 green 29 | * Arduino PIN 9 =================== RGB pin4 blue 30 | * Arduino GND =================== RGB pin2 GND 31 | * 32 | */ 33 | #define RGB_RED 11 34 | #define RGB_GREEN 10 35 | #define RGB_BLUE 9 36 | 37 | void setup() 38 | { 39 | pinMode(RGB_RED,OUTPUT); 40 | pinMode(RGB_GREEN,OUTPUT); 41 | pinMode(RGB_BLUE,OUTPUT); 42 | } 43 | 44 | void setColor(int red,int green,int blue) 45 | { 46 | analogWrite(RGB_RED,red); 47 | analogWrite(RGB_GREEN,green); 48 | analogWrite(RGB_BLUE,blue); 49 | } 50 | 51 | void loop() 52 | { 53 | int i; 54 | for (i=0; i<256; i++) 55 | { 56 | setColor(i, 0, 0); 57 | delay(4); 58 | } 59 | delay(500); //turn the RGB LED red smoth 60 | 61 | for (i=0; i < 256; i++) 62 | { 63 | setColor(0, i, 0); 64 | delay(4); 65 | } 66 | delay(500); //turn the RGB LED green smoth 67 | 68 | for (i=0; i < 256; i++) 69 | { 70 | setColor(0, 0, i); 71 | delay(4); 72 | } 73 | delay(100); //turn the RGB LED blue smoth 74 | } 75 | -------------------------------------------------------------------------------- /Lesson6-Buzzer/Buzzer.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson6-Buzzer/Buzzer.pdf -------------------------------------------------------------------------------- /Lesson6-Buzzer/buzzer/buzzer.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | 24 | 25 | [Title] product two frequeces sound 26 | [diagram] 27 | Arduino pin8 =================== buzzer positive wire 28 | 29 | */ 30 | int buzzer = 8; 31 | void frequence_1(void) // 1k HZ 32 | { 33 | int i ; 34 | for (i = 0; i < 80; i++) 35 | { 36 | digitalWrite(buzzer, HIGH); //sound production 37 | delay(1); 38 | digitalWrite(buzzer, LOW); 39 | delay(1); 40 | } 41 | } 42 | 43 | void frequency_2(void) // 500 HZ 44 | { 45 | int i ; 46 | for (i = 0; i < 100; i++) 47 | { 48 | digitalWrite(buzzer, HIGH); //sound production 49 | delay(2); 50 | digitalWrite(buzzer, LOW); 51 | delay(2); 52 | } 53 | } 54 | 55 | void setup() 56 | { 57 | pinMode(buzzer, OUTPUT); 58 | } 59 | void loop() 60 | { 61 | frequence_1(); 62 | delay(100); 63 | frequency_2(); 64 | } 65 | -------------------------------------------------------------------------------- /Lesson7-Flame Sensor/Flame Sensor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson7-Flame Sensor/Flame Sensor.pdf -------------------------------------------------------------------------------- /Lesson7-Flame Sensor/Flame_sensor/Flame_sensor.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] fire sensor control buzzer turn on/off 26 | * [diagram] 27 | * Arduino PIN 5 =================== fire sensor pin 28 | * Arduino PIN 9 =================== Active buzzer positive pole 29 | */ 30 | 31 | int fire_pin = A5; // define analog 5 pin for fire-sensor pin 32 | int buzzer = 9; // buzzer dirver pin 33 | int val = 0; 34 | int count = 0; 35 | void setup() 36 | { 37 | pinMode(buzzer,OUTPUT); // buzzer pin is output 38 | pinMode(fire_pin,INPUT); // fire-sensor pin is input 39 | Serial.begin(115200); // init baud rate is 115200 40 | digitalWrite(buzzer,LOW); // buzzer default value is 0 41 | } 42 | void loop() 43 | { 44 | val = analogRead(fire_pin); // get fire-sensor analog value 45 | Serial.println(val); 46 | if ( val < 600 ) // get value > 600 counet add 47 | { 48 | count++; 49 | } 50 | else { 51 | count = 0; 52 | } 53 | if( count >= 5 ) // count > 5 ensure infrared radiation found and give an alarm 54 | { 55 | digitalWrite(buzzer, HIGH); 56 | } else { 57 | digitalWrite(buzzer, LOW); // disable an alarm 58 | } 59 | delay(500); 60 | } 61 | -------------------------------------------------------------------------------- /Lesson8-SW520D/SW520D Vibration Switch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson8-SW520D/SW520D Vibration Switch.pdf -------------------------------------------------------------------------------- /Lesson8-SW520D/SW520D/SW520D.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] SW520D Ball Switch 26 | * [Diagram] 27 | * Arduino PIN A5 =================== SW520D PIN 1 28 | * Arduino PIN GND =================== SW520D PIN 2 29 | * Arduino PIN A5 =================== 10kΩresistor PIN 1 30 | * Arduino PIN 5V =================== 10kΩresistor PIN 2 31 | * Arduino PIN 13 =================== LED PIN + 32 | * Arduino PIN GND =================== LED PIN - 33 | */ 34 | int Led=13; 35 | int buttonpin=A5; 36 | int val=0; 37 | void setup() 38 | { 39 | pinMode(Led,OUTPUT); 40 | pinMode(buttonpin,INPUT); 41 | } 42 | void loop() 43 | { 44 | val=analogRead(buttonpin); 45 | if (val>512) { 46 | digitalWrite(Led,HIGH); 47 | } 48 | else { 49 | digitalWrite(Led,LOW); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Lesson9-4-Digit8-Segment Display/4-Digit 8-Segment Display.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/Lesson9-4-Digit8-Segment Display/4-Digit 8-Segment Display.pdf -------------------------------------------------------------------------------- /Lesson9-4-Digit8-Segment Display/LM35+_4-8Segment_Display/demo/demo.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | 24 | 25 | [Title] 4x8bit Numeric led Display the count down numble . 26 | [Diagram] 27 | Arduino PIN 2 =================== 8bit Numeric led a 28 | Arduino PIN 3 =================== 8bit Numeric led b 29 | Arduino PIN 4 =================== 8bit Numeric led c 30 | Arduino PIN 5 =================== 8bit Numeric led d 31 | Arduino PIN 6 =================== 8bit Numeric led e 32 | Arduino PIN 7 =================== 8bit Numeric led f 33 | Arduino PIN 8 =================== 8bit Numeric led g 34 | Arduino PIN 9 =================== 8bit Numeric led h 35 | Arduino PIN 10 =================== 8bit Numeric led D1 36 | Arduino PIN 11 =================== 8bit Numeric led D2 37 | Arduino PIN 12 =================== 8bit Numeric led D3 38 | Arduino PIN 13 =================== 8bit Numeric led D4 39 | Arduino PIN A5 =================== LM35 numble2 wire 40 | */ 41 | const int pinLM = A5; 42 | 43 | const int Vmax = 625; //5000:1024 44 | const int LMmax = 128; 45 | 46 | const int pinChoose[4] = {10, 11, 12, 13}; 47 | const int pinLCD[8] = {2, 3, 4, 5, 6, 7, 8, 9}; 48 | const int num[17] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x80}; 49 | // 0123456789 AbCdEF. + 17 50 | 51 | int flash = 2; 52 | void setup() 53 | { 54 | pinMode(pinLM, INPUT); 55 | for (int i = 0; i < 4; i++) 56 | { 57 | pinMode(pinChoose[i], OUTPUT); 58 | } 59 | for (int i = 0; i < 8; i++) 60 | { 61 | pinMode(pinLCD[i], OUTPUT); 62 | } 63 | Serial.begin( 9600 ); 64 | } 65 | 66 | void loop() 67 | { 68 | unsigned int t = analogRead(pinLM); 69 | t = t * Vmax / LMmax; 70 | Serial.println( t ); 71 | for (int i = 200; i; i--) 72 | { 73 | show_t( t ); 74 | } 75 | flash = ~flash; 76 | } 77 | 78 | void show_num(int nx) { 79 | for (int i = 0; i < 8; i++) 80 | digitalWrite(pinLCD[i], ((1 << i)&nx)); 81 | } 82 | 83 | void show_t(int x) { 84 | for (int i = 3; i >= 0; i--) { 85 | digitalWrite(pinChoose[i], LOW); 86 | if (x) { 87 | if ( i == flash ) { 88 | show_num( num[x % 10] | 0x80 ); 89 | } else { 90 | show_num( num[x % 10] ); 91 | } 92 | } else { 93 | show_num( 0x00 ); 94 | } 95 | delay(1); 96 | show_num( 0x00 ); //clean 97 | x /= 10; 98 | digitalWrite(pinChoose[i], HIGH); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Lesson9-4-Digit8-Segment Display/_4x7Segment_Display/_4x8Segment_Display.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * [Title] 4x8bit Numeric led Display the count down numble . 25 | * [Diagram] 26 | * Arduino PIN 2 =================== 8bit Numeric led a 27 | * Arduino PIN 3 =================== 8bit Numeric led b 28 | * Arduino PIN 4 =================== 8bit Numeric led c 29 | * Arduino PIN 5 =================== 8bit Numeric led d 30 | * Arduino PIN 6 =================== 8bit Numeric led e 31 | * Arduino PIN 7 =================== 8bit Numeric led f 32 | * Arduino PIN 8 =================== 8bit Numeric led g 33 | * Arduino PIN 9 =================== 8bit Numeric led h 34 | * Arduino PIN 10 =================== 8bit Numeric led D1 35 | * Arduino PIN 11 =================== 8bit Numeric led D2 36 | * Arduino PIN 12 =================== 8bit Numeric led D3 37 | * Arduino PIN 13 =================== 8bit Numeric led D4 38 | */ 39 | #define SEG_A 2 40 | #define SEG_B 3 41 | #define SEG_C 4 42 | #define SEG_D 5 43 | #define SEG_E 6 44 | #define SEG_F 7 45 | #define SEG_G 8 46 | #define SEG_H 9 47 | 48 | #define COM1 10 49 | #define COM2 11 50 | #define COM3 12 51 | #define COM4 13 52 | 53 | 54 | unsigned char table[10][8] = 55 | { 56 | {0,0,1,1,1,1,1,1}, //0 57 | {0,0,0,0,0,1,1,0}, //1 58 | {0,1,0,1,1,0,1,1}, //2 59 | {0,1,0,0,1,1,1,1}, //3 60 | {0,1,1,0,0,1,1,0}, //4 61 | {0,1,1,0,1,1,0,1}, //5 62 | {0,1,1,1,1,1,0,1}, //6 63 | {0,0,0,0,0,1,1,1}, //7 64 | {0,1,1,1,1,1,1,1}, //8 65 | {0,1,1,0,1,1,1,1} //9 66 | }; 67 | 68 | void setup() 69 | { 70 | pinMode(SEG_A,OUTPUT); 71 | pinMode(SEG_B,OUTPUT); 72 | pinMode(SEG_C,OUTPUT); 73 | pinMode(SEG_D,OUTPUT); 74 | pinMode(SEG_E,OUTPUT); 75 | pinMode(SEG_F,OUTPUT); 76 | pinMode(SEG_G,OUTPUT); 77 | pinMode(SEG_H,OUTPUT); 78 | 79 | pinMode(COM1,OUTPUT); 80 | pinMode(COM2,OUTPUT); 81 | pinMode(COM3,OUTPUT); 82 | pinMode(COM4,OUTPUT); 83 | } 84 | 85 | void loop() 86 | { 87 | Display(1,1); //bit1 display 1 88 | delay(500); 89 | Display(2,2); //bit2 display 2 90 | delay(500); 91 | Display(3,3); //bit3 display 3 92 | delay(500); 93 | Display(4,4); //bit4 display 4 94 | delay(500); 95 | } 96 | 97 | void Display(unsigned char com,unsigned char num) 98 | { 99 | digitalWrite(SEG_A,LOW); 100 | digitalWrite(SEG_B,LOW); 101 | digitalWrite(SEG_C,LOW); 102 | digitalWrite(SEG_D,LOW); 103 | digitalWrite(SEG_E,LOW); 104 | digitalWrite(SEG_F,LOW); 105 | digitalWrite(SEG_G,LOW); 106 | digitalWrite(SEG_H,LOW); 107 | 108 | switch(com) 109 | { 110 | case 1: 111 | digitalWrite(COM1,LOW); //select bit1 112 | digitalWrite(COM2,HIGH); 113 | digitalWrite(COM3,HIGH); 114 | digitalWrite(COM4,HIGH); 115 | break; 116 | case 2: 117 | digitalWrite(COM1,HIGH); 118 | digitalWrite(COM2,LOW); //select bit2 119 | digitalWrite(COM3,HIGH); 120 | digitalWrite(COM4,HIGH); 121 | break; 122 | case 3: 123 | digitalWrite(COM1,HIGH); 124 | digitalWrite(COM2,HIGH); 125 | digitalWrite(COM3,LOW); //select bit3 126 | digitalWrite(COM4,HIGH); 127 | break; 128 | case 4: 129 | digitalWrite(COM1,HIGH); 130 | digitalWrite(COM2,HIGH); 131 | digitalWrite(COM3,HIGH); 132 | digitalWrite(COM4,LOW); //select bit4 133 | break; 134 | default:break; 135 | } 136 | 137 | digitalWrite(SEG_A,table[num][7]); 138 | digitalWrite(SEG_B,table[num][6]); 139 | digitalWrite(SEG_C,table[num][5]); 140 | digitalWrite(SEG_D,table[num][4]); 141 | digitalWrite(SEG_E,table[num][3]); 142 | digitalWrite(SEG_F,table[num][2]); 143 | digitalWrite(SEG_G,table[num][1]); 144 | digitalWrite(SEG_H,table[num][0]); 145 | } 146 | -------------------------------------------------------------------------------- /Lesson9-4-Digit8-Segment Display/_4x8Segment_Display1/_4x8Segment_Display1.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * __ _ 3 | * / / _____ __ __ _ _ (_) ________ | | 4 | * / /____ / _____) \ \ / / | | __ | | | | ( ______) | |_____ 5 | * / / ___/ | |_____ \ \/ / | | / \ | | | | | |______ | ___ | 6 | * / /\ \ | |_____| \ / | | / /\ \ | | | | (_______ ) | | | | 7 | * / / \ \__ | |_____ / / | |/ / \ \| | | | ______| | | | | | 8 | * /_/ \___\ \______) /_/ \__/ \__/ |_| (________) |_| |_| 9 | * 10 | * 11 | * KeyWay Tech firmware 12 | * 13 | * Copyright (C) 2015-2020 14 | * 15 | * This program is free software: you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation, in version 3. 18 | * learn more you can see . 19 | * 20 | * This program is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * 25 | * [Title] 4x8bit Numeric led Display the count down numble . 26 | * [Diagram] 27 | * Arduino PIN 2 =================== 8bit Numeric led a 28 | * Arduino PIN 3 =================== 8bit Numeric led b 29 | * Arduino PIN 4 =================== 8bit Numeric led c 30 | * Arduino PIN 5 =================== 8bit Numeric led d 31 | * Arduino PIN 6 =================== 8bit Numeric led e 32 | * Arduino PIN 7 =================== 8bit Numeric led f 33 | * Arduino PIN 8 =================== 8bit Numeric led g 34 | * Arduino PIN 9 =================== 8bit Numeric led h 35 | * Arduino PIN 10 =================== 8bit Numeric led D1 36 | * Arduino PIN 11 =================== 8bit Numeric led D2 37 | * Arduino PIN 12 =================== 8bit Numeric led D3 38 | * Arduino PIN 13 =================== 8bit Numeric led D4 39 | */ 40 | #define d_a 2 41 | #define d_b 3 42 | #define d_c 4 43 | #define d_d 5 44 | #define d_e 6 45 | #define d_f 7 46 | #define d_g 8 47 | #define d_h 9 48 | 49 | #define COM1 10 50 | #define COM2 11 51 | #define COM3 12 52 | #define COM4 13 53 | 54 | unsigned char num[17][8] = { 55 | //a b c d e f g h 56 | {1, 1, 1, 1, 1, 1, 0, 0}, //0 57 | {0, 1, 1, 0, 0, 0, 0, 0}, //1 58 | {1, 1, 0, 1, 1, 0, 1, 0}, //2 59 | {1, 1, 1, 1, 0, 0, 1, 0}, //3 60 | {0, 1, 1, 0, 0, 1, 1, 0}, //4 61 | {1, 0, 1, 1, 0, 1, 1, 0}, //5 62 | {1, 0, 1, 1, 1, 1, 1, 0}, //6 63 | {1, 1, 1, 0, 0, 0, 0, 0}, //7 64 | {1, 1, 1, 1, 1, 1, 1, 0}, //8 65 | {1, 1, 1, 1, 0, 1, 1, 0}, //9 66 | {1, 1, 1, 0, 1, 1, 1, 1}, //A 67 | {1, 1, 1, 1, 1, 1, 1, 1}, //B 68 | {1, 0, 0, 1, 1, 1, 0, 1}, //C 69 | {1, 1, 1, 1, 1, 1, 0, 1}, //D 70 | {1, 0, 0, 1, 1, 1, 1, 1}, //E 71 | {1, 0, 0, 0, 1, 1, 1, 1}, //F 72 | {0, 0, 0, 0, 0, 0, 0, 1}, //. 73 | }; 74 | 75 | void setup() 76 | { 77 | pinMode(d_a,OUTPUT); 78 | pinMode(d_b,OUTPUT); 79 | pinMode(d_c,OUTPUT); 80 | pinMode(d_d,OUTPUT); 81 | pinMode(d_e,OUTPUT); 82 | pinMode(d_f,OUTPUT); 83 | pinMode(d_g,OUTPUT); 84 | pinMode(d_h,OUTPUT); 85 | 86 | pinMode(COM1,OUTPUT); 87 | pinMode(COM2,OUTPUT); 88 | pinMode(COM3,OUTPUT); 89 | pinMode(COM4,OUTPUT); 90 | } 91 | 92 | void loop() 93 | { 94 | for(int l = 0; l < 10; l++ ) 95 | { 96 | for(int k = 0; k < 10; k++) 97 | { 98 | for(int j = 0; j < 10; j++) 99 | { 100 | for(int i = 0;i < 10; i++) 101 | { 102 | //1000/8=125 103 | for(int q = 0;q<125;q++) 104 | { 105 | Display(1,l); 106 | delay(2); 107 | Display(2,k); 108 | delay(2); 109 | Display(3,j); 110 | delay(2); 111 | Display(4,i); 112 | delay(2); 113 | } 114 | } 115 | } 116 | } 117 | } 118 | } 119 | 120 | void Display(unsigned char com,unsigned char n) { 121 | digitalWrite(d_a,LOW); 122 | digitalWrite(d_b,LOW); 123 | digitalWrite(d_c,LOW); 124 | digitalWrite(d_d,LOW); 125 | digitalWrite(d_e,LOW); 126 | digitalWrite(d_f,LOW); 127 | digitalWrite(d_g,LOW); 128 | digitalWrite(d_h,LOW); 129 | 130 | switch(com) { 131 | case 1: 132 | digitalWrite(COM1,LOW); 133 | digitalWrite(COM2,HIGH); 134 | digitalWrite(COM3,HIGH); 135 | digitalWrite(COM4,HIGH); 136 | break; 137 | case 2: 138 | digitalWrite(COM1,HIGH); 139 | digitalWrite(COM2,LOW); 140 | digitalWrite(COM3,HIGH); 141 | digitalWrite(COM4,HIGH); 142 | break; 143 | case 3: 144 | digitalWrite(COM1,HIGH); 145 | digitalWrite(COM2,HIGH); 146 | digitalWrite(COM3,LOW); 147 | digitalWrite(COM4,HIGH); 148 | break; 149 | case 4: 150 | digitalWrite(COM1,HIGH); 151 | digitalWrite(COM2,HIGH); 152 | digitalWrite(COM3,HIGH); 153 | digitalWrite(COM4,LOW); 154 | break; 155 | default:break; 156 | } 157 | digitalWrite(d_a,num[n][0]); 158 | digitalWrite(d_b,num[n][1]); 159 | digitalWrite(d_c,num[n][2]); 160 | digitalWrite(d_d,num[n][3]); 161 | digitalWrite(d_e,num[n][4]); 162 | digitalWrite(d_f,num[n][5]); 163 | digitalWrite(d_g,num[n][6]); 164 | digitalWrite(d_h,num[n][7]); 165 | } 166 | -------------------------------------------------------------------------------- /NanoSchematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/NanoSchematic.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Please Contact Us 2 | Technical support email: support@emakefun.com
3 | Sales email: ken@emakefun.com
4 | The latest information download address:https://github.com/keywish/keywish-arduino-nano-kit
5 | 6 | # Nano-kit Feature 7 | `*Keywish Nano Kit is a super starter kit based on Nano V3.0 Micro-controller board,It has 60pcs components with detailed tutorial in a CD including project introduction and source code`
8 | `*The CD-ROM with ios, windows, linux three systems CH34x driver, no need to worry about driver incompatibility issues`
9 | `*It's the newest ultimate Nano Starter Kit with free PDF tutorial(11 lessons)`
10 | `*The Nano Mainboard with pin header (not need to be soldered by yourself)`
11 | `*The Nano Mainboard is using the chips ATmega328P and CH340, not FT232 as official Arduino,so pls. use the driver from this link:https://github.com/keywish/arduino-nano-kit`
12 | 13 | # Required Best Buy Links 14 | [Buy on Amazon](https://www.amazon.com/dp/B077ZN85MZ)
15 | [Buy on Aliexpress](https://www.aliexpress.com/store/product/Keywish-Nano-Super-Starter-Kit-With-Detailed-Tutorial-11-Lessons-User-Manual-Code-Library-For-Arduino/3269016_32845813810.html?spm=2114.12010615.0.0.3dc454149f6k4x) 16 | 17 | # download method 18 | ![](https://github.com/keywish/keywish-arduino-nano-kit/raw/master/image/Image.png) 19 | 20 | -------------------------------------------------------------------------------- /image/Download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/image/Download.png -------------------------------------------------------------------------------- /image/Image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keywish/keywish-arduino-nano-kit/a117658a3e421346ad824ad10fff634b8a1d6073/image/Image.png --------------------------------------------------------------------------------