Category Archives: Uncategorized

CNC Machine

I have had a MyDIYCNC Machine sitting around for a few years now. I was having some problems with the controller boards so I set it aside and am just getting back to take another look at it. I found that one of the boards that was sent to me was indeed bad but MyDIYCNC no longer sells machines or parts. I then decided to go to Amazon and pick out a controller board to try. I picked the SainSmart CNC TB6560 3 Axis Stepper Motor Driver Controller Board & Cable. This board seems to work quite well. I have been having a bit of a time getting it to work properly in LinuxCNC but I have got it to home and move but it seems to be at 1/2 scale. I am still tweaking with the settings to see if I can get it to work 100%.

A few notes about wiring and hardware. The MyDIYCNC instructions refer to the motor which moves the Z axis carrier as the Y axis. It appears that it should really be the X axis and the table should be the Y axis. If it were the Y axis, the home position would be in the wrong corner of the machine. I played with the configuration a bit to see if I could get it to work as expected but I had no luck. Finally when I decided to try to swap the X and Y axes did home line up in the correct corner. I could have swapped A & B around on the Y motor and that may have reversed the direction of the motor but I did not want to go there. Swapping the axes made the most sense.

Here is a short video of a test of the CNC. The spindle has a ink cartage in it and is simply running the default LinuxCNC project. The drawing should be 5.3 inches wide but is only half that size.

Here are the settings for LinuxCNC.

Base Information

  • Machine Name: MyDIYCNC_inches
  • Axis configuration: XYZ
  • Reset Default machine units: Inch
  • Driver type: Other
  • Driver Timing Settings (The Stepper Drive Timing page on states that 150,000 ns should be used for all values however the current version of LinuxCNC has a max value of 100,000.)
    • Step Time: 100000
    • Step Space: 100000
    • Direction Hold: 100000
    • Direction Setup: 100000
  • Base Period Maximum Jitter: 9000

Parallel Port 1

  • Outputs (PC to Mill):
    • Pin 1: Amplifier Enable (Invert)
    • Pin 2: X Step
    • Pin 3: X Direction
    • Pin 4: Y Step
    • Pin 5: Y Direction
    • Pin 6: Z Step
    • Pin 7: Z Direction
    • Pin 8: Unused
    • Pin 9: Unused
    • Pin 14: Spindle ON (Invert)
    • Pin 16: Unused
    • Pin 17: Unused
  • Inputs (Mill to PC):
    • Pin 10: Both Limit + Home X (Invert)
    • Pin 11: Both Limit + Home Y (Invert)
    • Pin 12: Both Limit + Home Z (Invert)
    • Pin 13: ESTOP In
    • Pin 15: Unused
  • Parport Base Address: 0
  • Output pinout presets: Sherline (The value here is not important. It is actually used with the “Preset” button to load values.)


Selections here really do not matter. I have not figured out how to use these yet. I may look into it more in the future.

Axis X

  • Motor steps per revolution: 800 (Steppers included with MyDIYCNC are 50 steps per revolution. The TB6560 board has the switches set for 1/16 microstepping. 50 x 16 = 800)
  • Driver Microstepping: 2.0 (Someone posted that 2 meant that microsteping was being used. I had this set to 32 earlier.)
  • Pulley teeth (Motor:Leadscrew): 1.0:1.0 (All axes are direct drive so they are all 1:1.)
  • Leadscrew Pitch: 20.0
  • Maximum Velocity: 0.4
  • Maximum Acceleration: 30.0
  • Home location: 0.125 This took awhile to get. If using the limit switches as home switches as well, we need to back the machine off so that the limit switches are not active when at home position. I choose to back them off 1/8 inch on all axes.)
  • Table travel: 0.0 to 5.5
  • Home Switch Location: 0.0
  • Home Search velocity: -0.05
  • Home Latch direction: Same

Axis Y

  • Motor steps per revolution: 800
  • Driver Microstepping: 2.0
  • Pulley teeth (Motor:Leadscrew): 1.0:1.0
  • Leadscrew Pitch: 20.0
  • Maximum Velocity: 0.4
  • Maximum Acceleration: 30.0
  • Home location: 0.125
  • Table travel: 0.0 to 8.0
  • Home Switch Location: 0.0
  • Home Search velocity: -0.05
  • Home Latch direction: Same

Axis Z

  • Motor steps per revolution: 800
  • Driver Microstepping: 2.0
  • Pulley teeth (Motor:Leadscrew): 1.0:1.0
  • Leadscrew Pitch: 20.0
  • Maximum Velocity: 0.4
  • Maximum Acceleration: 30.0
  • Home location: -0.125
  • Table travel: -4.0 to 0.0
  • Home Switch Location: 0.0
  • Home Search velocity: 0.05
  • Home Latch direction: Same

Almost Done

Do you want to quit?

Screenshot added for completeness

I plan to continue to look into what is going on with the scaling and settle on the correct settings or at least settings which will work.

Test Video

I would like to add more videos to the blog. One of the problems that I have had is the time it takes to perform post processing on videos to add different sources and information. I found the Open Broadcaster Software application and started messing around with it and found that it is quite good, once you get use to how it works. Here is my first attempt at creating a video with the software.

BTW: Yes, I totally ripped off some ideas from Adafruit. I’m not too creative so I copied what I like. I will attempt to change it but it is tough as Limor and Phil have created a very nice format for the shows that Adafruit produces. I also like Ben Heck and Dave Jones (EEVBlog) videos as well but I seem to watch more of the videos Adafruit puts out.

Here is my first recording.

Portable PI – Power Supply and Power Switch

Finally nearing the end of completing the power supply and soft latching power switch. The components have changed slightly but the principle design is the same. The components include two li-ion batteries connected in parallel with protection circuit, soft latching switch, Adafruit Powerboost 1000 with charging circuit (Product #2465) , and a Teensy 3.1. Along with the hardware components, there are two software pieces with one residing on the Teensy and the other running in the background of the Raspberry Pi.

The design utilizes a soft latching power switch has three functions. It powers the device on from an off state, signals the Teensy that the user has pressed the power button to request a shutdown, and power off. One of the main requirements besides those mentioned above is that the soft latching power switch must not draw current or very little current when in the off state. This is necessary as we do not want the batteries to be drained when the device is in the off state.

These requirements were met with a modified version of the soft latching power circuit described in my earlier post. The circuit was modified for a couple of reasons. First of all, the circuit needed to be able to operate from 3 to 4.5 VDC rather than at 5 VDC. Another reason the circuit needed to be modified is that the output was floating when off so the enable signal to the powerboost circuit would cause the power to cycle back on after a few seconds.

There are two pieces of software working together which allows the Raspberry Pi to safely shutdown when the user presses the power button. The Teensy has software which monitors the power button to see if it is pressed and monitors the USB power from the Raspberry Pi. If the user presses the power button, the Teensy changes the state of a pin on the Raspberry Pi. The Raspberry Pi has a program running in the background which checks if the logic level on the pin has changed. If the logic level changes, the script will issue a shutdown command.

The next thing was to determine the best way to know when the shutdown was complete.

Soft Latching Power Switch

The Raspberry Pi ON/OFF Power Controller that I looked at from Mosaic Industries, Inc. does a good job at 5 VDC but I need the circuit to be able to switch LiPo batteries which have a voltage range of between 2.7 and 4.35 VDC between discharged and fully charged. I looked for dual MOSFET devices which could operate in this range and found the following.

Both of these devices function at these lower voltages however I have been having some oscillation issues with these. When the button is held down to turn off the load, which is a LED, the output is switched off but it turns back on after a few seconds. I have not been able to investigate why this is happening. I suspect that I miswired something but I need to take some time to check.

The International Rectifier device seems to behave a bit better so it may be the one I use but I will need to investigate what the issue is and resolve that before I can move on. I can’t wait to wrap this project up.

If you have an idea as to what my problem may be, please leave a comment to let me know.

UPDATE – 16 May 2015

I determined the reason for the odd behavior was that the N-Channel MOSFET’s gate was floating. I was able to fix this by using a pull-down resistor of 100KΩ. Looking at the schematic, I connected the resistor between Pin 7 and ground. This pulls the gate to ground through the 330KΩ and 1KΩ resistors.

Weekly update

Dealing with PC issues at the moment so this week has been a bit rough.

My inspiration for the Portable Raspberry Pi came from the Ben Heck Show on Ben’s creation of a Portable Pi. (Part 1 & Part 2) I liked Ben’s design but there were a few things that I wanted to change.

  1. I did not want to deal with having a batteries in series and not be able to easily charge them in the case without disconnecting them from the device. This requirement was due to Ben’s choice of LCD monitor so I am changing the LCD to an Adafruit PiTFT screen which uses SPI. This will be a bit trickier to use but should not be a problem.
  2. I wanted to use the powerful Teensy for more than just the gamepad so I modified the Teensy code to provide a custom gamepad which has only the buttons that I will have plus provides keyboard and raw HID devices. The reason for these additional devices are for power management and control.
  3. Power – I wanted to be able to charge the battery in the device and still be able to use the device while it was charging. To implement this requirement, I turned to Adafruit’s USB LiIon/LiPoly charger.
  4. Power On/Off – The Portable Pi will be used by my children so I wanted to have an easy way for them to shut it down as well as to automatically shut it down when the batteries are low. This is where the additional Keyboard and Raw HID device come in on the Teensy. The plan is to implement a soft latching power switch circuit which can turn on the power to the device when pressed from an off state. When it is on, the Teensy will be able to detect when it is pressed and start an orderly shutdown of the Raspberry Pi. If the button is held down longer, about 3 seconds, then the power will be switched off. This will allow it to function much like the power switch on a PC or laptop.
  5. Power monitoring – I would also like to be able to monitor the battery level and perform an automatic shutdown of the Raspberry Pi if the voltage is too low. This is where the Raw HID device comes in. I plan to use the Teensy to monitor the battery voltage and send periodic updates to the Pi to let it know the level. If the level reaches a min threshold then it will send keypresses through the keyboard device to tell the Pi to shutdown.

These are just a few of the high level requirements I have for the Portable Pi. So far, I have the Gamepad code completed and the hardware on a breadboard. I am currently working on the soft latching power switch. I have built a few circuits which work but only at 5 VDC. I need it to work at 3 VDC and higher so I need to order some parts as I do not have MOSFETs which will switch full on at that low of a voltage. I plan to implement a design found on Mosaic Documentation Web. I have built a similar circuit and found it to work well and meet the requirements that I have. I also looked at David Jones’s design on his EEVBlog but it did not meet all of the requirements that I have. It is a nice simple design so I am certain I will use it in the future on another project.

Updates and Future Plans for this Blog

Well, I have done a terrible job keeping this blog up to date so I will try once again to do a better job. I plan to update this blog at least once a week by adding an update even if I feel there is not much to report. The plan is to do a blog entry each Monday by 10 PM EST.

Some updates since my last blog post.

I have managed to be on Adafruit’s Show and Tell a few times. Adafruit’s Show and Tell is hosted by Google Plus Hangouts.

  • 18 Jan 2014: Pinewood Derby Car
  • 26 Nov 2014: Guggenhat with mods
  • 31 Dec 2014: LED Matrix Clock and Eiffel Tower Alarm Clock
  • 11 March 2015: Power Supply

I am currently working on a Portable Pi. It is a slightly different design than any of the others I have seen posted online. Most likely the next few posts will be regarding the build of the Portable Pi. Once that is completed, I plan to post a few of the builds mentioned in the Adafruit Show and Tell segments such as the power supply, Guggenhat mods, and LED Matrix Clock mod.

Raspberry PI B+



  • Raspberry Pi
  • MicroSD Card 4GB or larger
  • USB Keyboard
  • USB Power Supply and cable with micro USB Connector
  • Display (Composite or HDMI)
  • Display cable (Type of cable depends on monitor)
  • MicroSD Card to SD Card Adapter (Needed only if your PC has a SD Card Reader but not a MicroSD Card Reader)

Nice to Have

  • Raspberry Pi B+ Case (Note cases for other models may not work)
  • WiFi module or Ethernet Cable


  1. Download the Raspbian Image from (As of this post, the file is
  2. Unzip the Raspbian Image File
  3. Follow the instructions at for your operating system. I will be using Windows and will mirror the steps from the installation instructions page

Windows Installation

  1. Insert your MicroSD card into the card reader on your PC (NOTE: You may need a MicroSD to SD Card Adapter)
  2. Download the Win32DiskImager utility from (As of this post, the file is Win32DiskImager-0.9.5-install.exe)
  3. Install the Win32DiskImager Utility by double clicking the downloaded file
  4. Click on the “Next >” button on the setup wizard
    Welcome to the Win32DiskImager Setup Wizard
  5. Select the “I accept the agreement” radio button and click the “Next >” button
    License Agreement
  6. Click the “Next >” button on the destination location dialog
    Select Destination Location
  7. Click the “Next >” button on the Select Start Menu Folder dialog
    Select Start Menu Folder
  8. If you do not want a desktop shortcut, uncheck the “Create a desktop icon” checkbox
  9. Click the “Next >” button on the Select Additional Tasks dialog
    Select Additional Tasks
  10. Click the “Install” button on the Ready to Install dialog
    Ready to Install
  11. Wait for the installation to complete
  12. Click the “Finish” button on the Completing the Win32DiskImager Setup Wizard dialog
    Completing the Win32DiskImager Setup Wizard
  13. It is possible that you may see the following error message
    Unable to execute file
  14. If you see the error message above
    1. Click the “OK” button
    2. Right-click on the desktop shortcut and select “Run as administrator” from the pop-up menu
      Run as administrator
    3. When the User Access Control dialog is displayed, click the “Yes” button
      User Access Control dialog
  15. The application is now open
    Win32 Disk Imager
  16. Click the folder icon and select the Raspbian image file downloaded earlier
    Selecting the image file
  17. Select the drive letter for your MicroSD Card
    WARNING: Be very careful to select the correct drive letter as the utility will erase all data on the drive! You have been warned!
    Select the MicroSD Card
  18. Click the “Write” button
    Write the image
  19. Click the “Yes” button on the confirmation dialog
    Confirm Write
    If you see the following error (), check that there are no open Explorer Windows or other applications attempting to access the SD Card
    Write Error
    If you see the following error, check the write lock switch on the MicroSD Card Adapter
    Lock Error  SD Card Lock Switch
    Wait for the process to complete
  20. When the process is complete, click the “OK” button
    Write Sucessful
  21. The main window will display the status as “Done.” Click the “Exit” button to exit the utility
  22. Eject the MicroSD Card

Once the Raspbian Image has been written to the MicroSD Card, you are ready to boot and configure the Operating System (OS).

Booting and Configuring the Raspberry Pi using Raspbian OS

  1. Insert the MicroSD Card in the Raspberry Pi
  2. Connect the monitor, keyboard, mouse (optional), and power
  3. The Raspberry Pi Software Configuration Tool (raspi-config) will launch

A look at Adafruit’s Electret Microphone Amplifier – MAX4466 with Adjustable Gain (1063)

I purchased Adafruit’s Electret Microphone Amplifier – MAX4466 with Adjustable Gain (1063) and wanted to incorporate the circuit into a board that I am making to make a sound responsive decorative light. I saw a post from Adafruit that stated that the schematic was taken directly from the datasheet however looking at the component values on the board, it was obvious that some values had been changed. After a bit of reverse engineering of the board, it was confirmed that the schematic is indeed Figure 2 from the datasheet.


Board Layout

Component Listing (Note Capacitor Values taken from Datasheet Schematic and not verified)

      • IC1 – MAX4466
      • R1 – 1KΩ
      • R2 – 1KΩ
      • R3 – 1MΩ
      • R4 – 1MΩ
      • R5 – 1KΩ
      • R6a – 500KΩ
      • R6b – 22KΩ
      • C1 – 0.1µF
      • C2 – 0.01µF
      • C3 – 1µF
      • C4 – 100pF
      • L1 – Ferrite Bead
      • L2 – Ferrite Bead

I wrote a simple program on the Arduino to capture 100 points of data per second for one minute and write the results to the serial output.

Here is the circuit diagram for the first test with values from the datasheet.


Test Schematic 1 – Values from datasheet

At first, I tried to use the values from the datasheet and noticed that the gain was not as high as the Adafruit module.


Adafruit (ID: 1063) and MAX4466 Typical Schematic


Adafruit (ID: 1063) Capture


MAX4466 Schematic from Datasheet

Modified values to be close to the values used by the Adafruit 1063 module. The results showed that the gain was much better so these values will be good enough for my application, If you need to use this for a different application where you need better performance, you may want to look into the RC values. By modifying the capacitor values, it may be possible to achieve a cleaner output.


Modified resistor values to match Adafruit 1063 module


Adafruit (ID: 1063) and MAX4466 Typical Schematic modified values


Adafruit (ID: 1063)


MAX4466 Typical Schematic modified values

This is not a thorough analysis of the performance of these two circuits but as stated above, it was good enough to give me the performance that I needed. (Test with Datasheet Figure 2)

BTW: The values read by the Arduino ADC are between 0 and 1023. The signal is centered around 511 and  has a noise level of ±50.

FYI: The gain for the circuit may be calculated as:

Gain = Rf/Rin = R6/R5 = 100KΩ/10KΩ = 10 (Dtasheet Circuit)

Gain = Rf/Rin = R6/R5 = 120KΩ/1KΩ = 120 (Modified Circuit)

You can also see from the graphs that the amplifier is driven to saturation. For my application that is acceptable but it may not be acceptable for your application particularly if you are creating a purely audio application.

Arduino Due Issues

I have been working with the Arduino Due and version 1.5.2 of the Arduino IDE. I have been attempting to port a mini digital picture frame that I wrote for the Arduino Micro and have not been having much luck. The problem is that the Arduino Due is still relatively new and is a different family than the previous Arduinos.

The errors that have been encountered due to references to the avr libraries. (In particular avr\io.h and avr/pgmspace.h.)

In my attempt, I did the following:

  1. Created the program shown below to workout the library issues. Once I am able to resolve the library issues, I will be able to start porting the code.
  2. Replace the Adafruit_ST7735 library with the modified version at” target=”_blank which has been modified to support the Arduino Due
  3. Update the Adafruit_GFX library with the changes found at
  4. Create a new folder in the Arduino IDE location at hardware/arduino/sam/cores/arduino/avr/
  5. Create a new file at hardware/arduino/sam/cores/arduino/avr/pgmspace.h and enter contents found at

Some issues are resolved but others remain.


#include <Adafruit_GFX.h> // Core graphics library // OK after changes to libraries
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h> // OK
// #include <SD.h>

void setup() {
// put your setup code here, to run once:


void loop() {
// put your main code here, to run repeatedly:



In file included from sketch_may19a.ino:20:
C:\arduino-1.5.2\libraries\Adafruit_ST7735/Adafruit_ST7735.h: In member function 'uint16_t Adafruit_ST7735::Color565(uint8_t, uint8_t, uint8_t)':
C:\arduino-1.5.2\libraries\Adafruit_ST7735/Adafruit_ST7735.h:116: error: 'newColor' was not declared in this scope

Commented line 20 in the Adafruit_ST7735.h file as the Color565 function does not appear to be called elsewhere and the newColor function does not exist in any libraries. The following errors are then produced.

C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(uint8_t*)':
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:266: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:268: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:276: error: 'SPI_CLOCK_DIV4' was not declared in this scope
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:283: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment
C:\arduino-1.5.2\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:285: error: cannot convert 'volatile RwReg*' to 'volatile uint8_t*' in assignment

Why is it when people provide fixes they are rarely documented completely? This is one of the most frustrating things that I encounter. I can solve these issues if given enough time but unfortunately I do not have the luxury. I will come back to this later and attempt to resolve the remaining issues.

Here is a post of someone else trying to get the Adafruit display to work with the Arduino Due.

To be fair, the Arduino Due is a totally different architecture and it will take time to port the libraries over to the new architecture. I hope to get some more time later to tackle this problem again as this is a great opportunity to learn more about the Arduino Due but I suspect that I will not be able to devote the time I need to accomplish much.

Setting up the WiFi Part I – Supported Adapters

Video Coming Soon

This entry is for configuring the Asus USB-N10 USB Wireless-N USB Adapter. If you have any other WiFi adapter please refer to Chapter 4 Network Configuration of the Raspberry Pi User Guide book or perform Google Searches for your adapter.


NOTE: There is a WiFi Config tool included with Raspbian “wheezy” distribution however I have not had much luck with it. I t did work one time for me and that was it. You may give it a try but I recommend using the steps below as they have worked 100% of the time for me.


You will need to perform these steps from the command line. If you have the desktop loaded, open a terminal window by double clicking on the the LXTerminal shortcut on the desktop.

  1. At the command line, type the following command and press enter to view available wireless networks.
    sudo iwlist scan | less
  2. On the wlan interface, you will see the SSIDs listed on the lines starting with ESSID:. Verify that the network you wish to connect to is listed.
  3. Press Ctrl+z to return to the command line
  4. Edit the network configuration file by typing the following command and press enter.
    sudo nano /etc/network/interfaces
  5. You should see the following content in the interfaces file.
    auto loiface lo inet loopback
    iface eth0 inet dhcpallow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp


  6. Replace the bottom block with the following.
    auto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa.conf


  7. The resulting file should have the following contents.
    auto loiface lo inet loopback
    iface eth0 inet dhcpauto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa.conf


  8. Save the file and exit
    • Press Ctrl+o
    • Press Enter
    • Press Ctrl+x
  9. Now edit the wpa.conf file by typing the following command and pressing enter.
    sudo nano /etc/wpa.conf
  10. Enter the following for the contents of your file based on the type of security used by your WiFi network.
    NOTE: Do not type the word [Tab]. It indicates that you need to include a tab.

    No Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=NONE
    WEP Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=NONE
    [Tab] wep_key0=”Your_WEP_Key
    WPA/WPA2 Encryption network={
    [Tab] ssid=”Your_SSID
    [Tab] key_mgmt=WPA-PSK
    [Tab] psk=”Your_WPA_Key


  11. Save the file and exit
    • Press Ctrl+o
    • Press Enter
    • Press Ctrl+x
  12. Connect to the wireless network by typing the following command and pressing enter.
    sudo ifup wlan0
  13. If you see the message “ifup: interface wlan0 already configured,” type the following command and repeat the previous step again.
    sudo ifdown wlan0
  14. If you are successful, you will see several lines starting with DHCPDISCOVER on wlan0 to port 67 … with the last line stating that the adapter is bound to an IP address on your network
  15. If you are successful at this point, you may close the terminal window and open a web browser to verify that you are connected to the internet.