Showing posts with label Buy. Show all posts
Showing posts with label Buy. Show all posts

2016/08/24

How to use the UART of Raspberry Pi for wireless communication - part 2

This is a quick summary of how to connect Raspberry Pi to a 433MHz Serial to Wireless module (HC-11 / HC-12) and how to program the Pi using Python to receive incoming data.

Before the Pi's UART can be used for this purpose, there are some preparations that need to be made. Please refer to http://wei48221.blogspot.tw/2016/08/how-to-use-uart-of-raspberry-pi-for_99.html for info. on how to prepare the Pi's UART.

Schematic:




Checking the version of the installed Python.

Issue "python --version".


Install pySerial

Issue "sudo apt-get install python-serial".

Other preparation works

Create a folder call "python" (if it hasn't been created) to keep the python programs.

1. Issue "mkdir python" to create the python folder.

2. Issue "ls" to make sure the folder is created.


Change working directory to the newly created python folder.

"cd python"

Launch nano text editor and name the file created "serial_read.py"

"nano serial_read.py"

Code

Type in the code between the 2 dash lines.
----------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env python

import time
import serial

ser = serial.Serial(
         port='/dev/ttyAMA0',
         baudrate = 9600,
         parity=serial.PARITY_NONE,
         stopbits=serial.STOPBITS_ONE,
         bytesize=serial.EIGHTBITS,
         timeout=1
         )
counter=0
   
while 1:
         x=ser.readline()
         print x
---------------------------------------------------------------------------------------------------------------------
IMPORTANT!!

Watch out for the indent as python uses spacing at the start of the line to determine when code blocks start and end (http://stackoverflow.com/questions/1016814/what-to-do-with-unexpected-indent-in-python).

Save the program.
Ctrl-X to exit the editing mode, then "Y" to save the file.

Running the program 

"python serial_read.py".

Here I have an Arduino Uno with some sensors and a HC-11 module attached to it. Whenever a sensor is triggered, the Uno will send a message out via the HC-11 module. The message is picked up by the "serial_read.py " running on the Raspberry Pi and displayed in the PuTTY terminal.


When we are done with the program, use Ctrl-C to stop its execution.

References:

Using UART on Raspberry Pi – Python
https://electrosome.com/uart-raspberry-pi-python/

Arduino Lesson 17. Email Sending Movement Detector
https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/python-code

Read and write from serial port with Raspberry Pi
http://www.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/

---------------------------------------------------------------------------------------------------------------------

Product Offered:

Note, the 2 modules listed here have been tested to work with Arduino Uno and Raspberry Pi.

433MHz Serial RF Module -- HC-11


- Price: US$6.99/ea;
- Item Location: Taipei, Taiwan;
- Range: ~100 Meters (direct line of sight without obstruction);
- Frequency: 433MHz;
- Operating Voltage: DC 3.3V ~ 5V (when feeding DC 3.3V to the VCC of the module, the module works with Raspberry Pi without the need for level shifting / voltage division);
- Serial baud rate: 1.2Kbps to 115.2Kbps (default 9.6Kbps);
- Interface protocol: UART/TTL;
- At least 2 HC-11 modules are needed to form a complete wireless link.

IMPORTANT - THIS MODULE DOESN'T WORK WITH THE 433MHz Serial RF Module HC-12.

-------------------------------------------------------------------------------------------------------------------------

433MHz Serial RF Module -- HC-12
- Price: US$7.99/ea;
- Item Location: Taipei, Taiwan;
- Range: ~1000 Meters (@ 5000bps) direct line of sight without obstruction);
- Frequency: 433MHz;
- Operating Voltage: DC 3.3V ~ 5V (when feeding DC 3.3V to the VCC of the module, the module works with Raspberry Pi without the need for level shifting / voltage division);
- Serial baud rate: 1.2Kbps to 115.2Kbps (default 9.6Kbps);
- Interface protocol: UART/TTL;
- At least 2 HC-12 modules are needed to form a complete wireless link.

IMPORTANT - THIS MODULE DOESN'T WORK WITH THE 433MHz Serial RF Module HC-11.

How to purchase:

Leave your message in the comment section below or send me an e-mail. I will contact you for detail.

2016/08/09

Raspberry Pi - Setting up WiFi using USB WiFi Dongle based on Realtek RTL8188CUS chipset

This is a quick summary of how to set up WiFi using USB WiFi Dongle based on Realtek RTL8188CUS chipset.

1. Make sure the Raspberry Pi is power off.

2. Plug in a USB WiFi Dongle that uses Realtek RTL8188CUS chipset to one of the USB ports of the Raspberry Pi.

3. Power on the Raspberry Pi.

4. Use PuTTY to login to Raspbian.

5. Issue the "sudo lsusb" command to list the USB devices attaching to the Raspberry Pi.




6. Issue the "sudo nano /etc/network/interfaces" command to bring up the interface configuration file for editing.


Note from the configuration above that hotplug is supported. That is, if the USB WiFi Dongle is plugged into the USB port AFTER the Raspberry Pi is powered up, the OS is able to detect and enable support for the USB WiFi Dongle. 

Make sure the instructions in the red box above are exactly the same as the 4 lines of instruction below.

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Press “CTRL + X” to exit nano (press Y and then press ENTER when prompted) to save and exit.

7. Issue the "sudo iwlist wlan0 scan" command to scan and list available WiFi hotspots. Use the scroll bar on the right to scroll through the list.


8. Issue the "sudo nano /etc/wpa_supplicant/wpa_supplicant.conf" command to edit the "wpa_supplicant.conf" file.

Add the following line to the file.

network={
        ssid="YourSSID"
        psk="password"
        key_mgmt=WPA-PSK
}


Press “CTRL + X” to exit nano (press Y and then press ENTER when prompted) to save and exit.

9. Issue "sudo reboot" to reboot the Raspberry Pi.

Verification

1. Unplug the RJ-45 Ethernet cable (if it's still connecting the Raspberry Pi to the router) from and use Advanced IP Scanner to scan for the IP address of the Raspberry Pi's WiFi port.


In my case, the IP address assigned by the router to the WiFi Dongle plugged into the Raspberry Pi is 192.168.1.24.

2. Use PuTTY to login to the Rspberry Pi via its WiFi port and use the ping command to make sure the Pi is connected to the internet.


Note,

- To store multiple SSIDs and passwords for different networks, simply repeat the network={…} code in the wpa_supplicant.conf file for each network.

- The instruction above is for WiFi network that uses visible SSID, for WiFi network that uses hidden SSID, please refer to this post - http://www.dafinga.net/2013/01/how-to-setup-raspberry-pi-with-hidden.html.

References:

How to set up WiFi on a Raspberry Pi
https://www.maketecheasier.com/setup-wifi-on-raspberry-pi/

Setting up Wifi with the Command Line
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis

--------------------------------------------------------------------------------------------------------------------------

Product Offered:

USB WiFi Dongle (based on Realtek RTL8188CUS Chipset) - US$4/ea


Description:

- This is exactly the same dongle that I used for writing this post.
- It works with Raspbian JESSIE out of the box. All you need to do is follow the above instruction to make some changes to the configuration files.

How to purchase:

Leave your message in the comment section below and I will contact you for detail.

2016/07/05

DIY filament extruder kit for making filament from raw or used material for 3D printing

This post is a quick summary of the v1 version extruder made for making filament from raw or used material for 3D printing.

Info. about the v2 version with more powerful motor can be found at
http://wei48221.blogspot.tw/2016/10/filament-extruder-v2.html.

The extruder can be operated horizontally or vertically.

Horizontal Operation

2016/06/21

Interfacing a RC transmitter with a computer

This post is about how to interface a RC transmitter for plane / boat / car with a computer. The purpose of doing so is to use the RC transmitter to control the games / simulators running on the interfaced computer. For this post, I will be using DEVO 7E and RX601, but this post is applicable to any RC transmitter and receiver pair that works with Servo motor similar to the one shown below.

DEVO 7E Transmitter and RX601 Receiver
3-wire Servo 

How it works?

An Arduino Uno board is used to take in the PWM signals from the PWM outputs of the receiver. The PWM signals are then processed by the software running on the Arduino Uno board to come out with the control signals to be fed to the computer connected to the Arduino Uno board via a USB cable. The computer treats the input signals as from a connected joystick and the signals are used to control the games / simulators running on the computer.

The PWM waveforms

Before a program can be made to process the PWM signals, we need to know how they look. The photo below shows the division of the channels on the RX601 receiver.

The waveform of the PWM output of each channel on the receiver are shown below.










Code

#include "UnoJoy.h"

int tmp;
unsigned long time_now;

void setup(){

  setupPins();
  setupUnoJoy();
}

void loop(){
  // Always be getting fresh data

  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);
}

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the
  // two serial line pins

  for (int i = 2; i <= 12; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(A4, INPUT);
  digitalWrite(A4, HIGH);
  pinMode(A5, INPUT);
  digitalWrite(A5, HIGH);

  // RX601 Receiver CH1 Input,
  pinMode(A0, INPUT);
 
}

dataForController_t getControllerData(void){

  //  Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before

  dataForController_t controllerData = getBlankDataForController();

  //  Since our buttons are all held high and
  //  pulled low when pressed, we use the "!"
  //  operator to invert the readings from the pins
  //  The section below is not used in our application.
  //---------------------------------------------------------------
  controllerData.triangleOn = !digitalRead(2);
  controllerData.circleOn = !digitalRead(3);
  controllerData.squareOn = !digitalRead(4);
  controllerData.crossOn = !digitalRead(5);
  controllerData.dpadUpOn = !digitalRead(6);
  controllerData.dpadDownOn = !digitalRead(7);
  controllerData.dpadLeftOn = !digitalRead(8);
  controllerData.dpadRightOn = !digitalRead(9);
  controllerData.l1On = !digitalRead(10);
  controllerData.r1On = !digitalRead(11);
  controllerData.selectOn = !digitalRead(12);
  controllerData.startOn = !digitalRead(A4);
  controllerData.homeOn = !digitalRead(A5);
  //--------------------------------------------------------------

  // Get the input from CH1 of RX601

  while (digitalRead(A0) == LOW) {}
  time_now = micros();
  while (digitalRead(A0) == HIGH) {}
  tmp = micros() - time_now;
  controllerData.leftStickX = tmp >> 2;
  //Serial.println(tmp);

  while (digitalRead(A1) == LOW) {}
  time_now = micros();
  while (digitalRead(A1) == HIGH) {}
  tmp = micros() - time_now;
  controllerData.leftStickY = tmp >> 2;
  //Serial.println(tmp);

  while (digitalRead(A2) == LOW) {}
  time_now = micros();
  while (digitalRead(A2) == HIGH) {}
  tmp = micros() - time_now;
  controllerData.rightStickX = tmp >> 2;
  //Serial.println(tmp);

  while (digitalRead(A3) == LOW) {}
  time_now = micros();
  while (digitalRead(A3) == HIGH) {}
  tmp = micros() - time_now;
  controllerData.rightStickY = tmp >> 2;
  //Serial.println(tmp);

  // And return the data!
  return controllerData;
}

Demo Video

Click here to play the demo video on Youtube.


For more about how to prepare Arduino Uno for the above application, please refer to the posts mentioned in the reference section below.

References

How to use Unojoy with Arduino Uno

How to turn Arduino Uno into HID Keyboard - Part 2 of 2

How to turn Arduino Uno into HID Keyboard - Part 1 of 2
http://wei48221.blogspot.tw/2016/06/arduino-uno-hid-keyboard-joystick-part.html

---------------------------------------------------------------------------------------------------------------------

Buying Info.

I've prepared a kit that contains one Arduino Uno board pre-configured and pre-loaded with the necessary software and accessories (see below photos for the included items). Please e-mail me if you want to order or have any questions.

Price: US$30 per kit;
Shipping: Free shipping for order over US$50 to most major countries (please contact me to see if free shipping is applicable to your location);
Tax and tariffs: To be paid by the buyer;
Item location: Taipei, Taiwan;
Items included:
- 1 x Arduino Uno board;
- 1 x USB cable;
- 6 x Jumping wires with connectors.


The photo below shows how to connect the RX601 with the Arduino Uno board.



2016/06/07

What can be done with a DIY 3D Printer?

This post contains photos and brief descriptions of the things that I made with my DIY 3D printers (see below photo for reference). More will be added as I make more stuff with them.


DIY 30cm x 30cm x 30cm Prusa i3 3D Printer


The cap of blender cover

The 2 latches of the cap of my blander cover were broken, so I drew a new one and printed it out using a white flexible filament. It's a perfect match and my wife is happy.. :-)


Spheres for parachute

I saw an interesting video on Youtube (https://www.youtube.com/watch?v=sdF1lcoNt1Y) that teaches the making of throw-able parachute. As I don't have access to the ball used in the video, I drew 2 types of spheres (smaller one with holes, bigger one without hole) and use used plastic bag (left), and PVC cloth (right) to make the parachute.


The gears and wheels of DIY camera trolley

I use flexible filament for the wheel and PETG for the gears of the camera trolley that I built. This trolley is capable moving back and forth and rotating the camera at the same time or separately. The trolley is controller by Arduino plus my custom-made motor driver board..


Docking station enclosure

This is an enclosure that I made for a friend to fit different connectors. Because the size of this enclosure cannot fit into the printing envelop of my DIY 20cm x 20cm x 20cm printer, I built a 30cm x 30cm x 30cm Prusa i3 style printer to print it.


The funnel base for the DIY extruder for making 3D printing filament

Click here for the time lapse video of the printing process.



Where to buy?

3D Printer - 30 - Free Shipping
http://wei48221.blogspot.tw/p/products.html#!/3D-Printer-30-Free-Shipping/p/62075835/category=17963923

--------------------------------------------------------------------------------------------------------------------------

Other People's Projects

Building an Enclosure using SketchUp and 3D Printing
http://bikerglen.com/blog/building-an-enclosure-using-sketchup-and-3d-printing/