2016年6月20日 星期一



How to find the driver (module) associated with a device on Linux?


udevadm info -a -n /dev/sda | grep -oP 'DRIVERS?=="\K[^"]+' 
sd
ahci

arduino usb2ttl  ->   choose ch341 device driver


Ref : http://unix.stackexchange.com/questions/97676/how-to-find-the-driver-module-associated-with-a-device-on-linux


Have you ever wondered why some USB devices used /dev/ttyUSB0(or 1, or n) and others/dev/ttyACM0 (or 1, or n) when they are plugged into the host computer, while they seem to be acting asUART devices (RS-232-like) over USB in both cases? Have you wondered why example USB firmwares for microcontrollers always end up with names such as /dev/ttyACM0 and never as/dev/ttyUSB0?
Warning: this is a Linux specific post, although it also contains genuine pieces of USB culture.

Ref : https://www.rfc1149.net/blog/2013/03/05/what-is-the-difference-between-devttyusbx-and-devttyacmx/

2016年6月15日 星期三

wifi sample



Hardware board

CC3000





Next, connect the enable and interrupt lines: 
VBEN to Digital 5
 IRQ to Digital 3 

 Now, connect 
 SPI: CLK to Digital 13
 MISO to Digital 12
 MOSI to Digital 11 
 CS to Digital 10


#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! 
#define WLAN_PASS "myPassword" 
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or //WLAN_SEC_WPA2 
#define WLAN_SECURITY WLAN_SEC_WPA2 

// On an UNO, SCK = 13, MISO = 12, and MOSI = 11

//
Adafruit_CC3000(uint8_t csPin, uint8_t irqPin, uint8_t vbatPin, uint8_t spispeed = SPI_CLOCK_DIVIDER);

begin(uint8_t patchReq = 0, bool useSmartConfigData = false);




sample code 如下:


#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "myNetwork"           // cannot be longer than 32 characters!
#define WLAN_PASS       "myPassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define LISTEN_PORT           23    // What TCP port to listen on for connections.

Adafruit_CC3000_Server chatServer(LISTEN_PORT);

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);

  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }

  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
 
  Serial.println(F("Connected!"));

  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  /* Display the IP address DNS, Gateway, etc. */
  while (! displayConnectionDetails()) {
    delay(1000);
  }

  /*********************************************************/
  /* You can safely remove this to save some flash memory! */
  /*********************************************************/
  Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches"));
  Serial.println(F("since the .disconnect() function is never called, so the"));
  Serial.println(F("AP may refuse connection requests from the CC3000 until a"));
  Serial.println(F("timeout period passes.  This is normal behaviour since"));
  Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n"));

  // Start listening for connections
  chatServer.begin();

  Serial.println(F("Listening for connections..."));
}

void loop(void)
{
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = chatServer.available();
  if (client) {
     // Check if there is data available to read.
     if (client.available() > 0) {
       // Read a byte and write it to all clients.
       uint8_t ch = client.read();
       chatServer.write(ch);
     }
  }
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;

  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}


Ref : https://www.openhacks.com/uploadsproductos/adafruit-cc3000-wifi.pdf

2016年6月13日 星期一

A4988 和 cnc shield 的研究






int dirPin = 8;
 int stepperPin = 7; 
void setup() { 
      pinMode(dirPin, OUTPUT); 
     pinMode(stepperPin, OUTPUT); 
   } 
void step(boolean dir,int steps){ 
digitalWrite(dirPin,dir);
delay(50); 
    for(int i=0;i<steps;i++){ 
        digitalWrite(stepperPin, HIGH); 
        delayMicroseconds(800); 
       digitalWrite(stepperPin, LOW); 
       delayMicroseconds(800); } 
void loop(){
step(true,1600); 
delay(500); 
step(false,1600*5); 
delay(500); } 



Clone X-Axis to the 4th stepper driver(Marked as A)


Use D12 and D13 to drive the 4th stepper driver(Marked as A)



End Stop Configuration
By default GRBL is configured to trigger an alert if an end-stop goes low(Gets grounded).
On the forums this has been much debated and some people requested to have active
High end-stops. The jumpers in the picture provides the option to do both. (To run with
default setting on GRBL the jumper need to be connected like the left shield in the image
below)(This Jumper was only introduced in Version 3.02)

active low -> 左圖...

active high -> 右圖