I know that the Raspberry Pi has its own GPIO pins, but since I had
absolutely no experience with this kind of thing, I preferred to use an
Arduino for that. But, as Polymath Universata has shown
in a number of posts, there is nothing that prevents you from hooking
up the Arduino to your Raspberry Pi. That saves you the cost of buying
an Ethernet-shield for your Arduino.
It was one of those “combine what others have figured out for you”
projects. It involves a DHT11 temperature & humidity sensor, a
breadboard, a 10K resistor, some wires, an Arduino, a USB-cable, a
Raspberry Pi, an Apache webserver, some Pythone code and some time.Wiring up the DHT11
The nice people at Adafruit not only sell you the DHT11, they also have a number of pages that explain you how to wire up the DHT11, provide you with a library and example code to get started.
The result is that you will be able to see the temperature and humidity in the Arduino IDE.
But that of course is not enough.
Setting up the Raspberry Pi
The cool thing, that makes this setup work, is that the Raspberry Pi can do exactly what the Arduino IDE can do: listen to the data that is sent over the serial interface by the Arduino.
So if we connect the Arduino to one of the two Raspberry Pi USB-ports, you can make the Raspberry Pi listen to that data.
You need a Python library for serial communications called ‘pySerial‘.
Since I do everything over SSH, I couldn’t simply follow Dr. Monk’s instructions but did it slightly different:
1. On your laptop/Mac go to http://sourceforge.net/projects/pyserial/files/pyserial/2.5/
2. Download pyserial-2.5.tar.gz
3. Unzip it
4. Connect to your Raspberry Pi using WinSCP
5. Upload the pyserial folder to a temp folder on your Raspberry Pi
6. Connect using SSH
7. Go to the temp folder
8. sudo python setup.py install
I needed to do a couple of things not listed in the post by Dr. Monk:
9. type: sudo usermod -a -G dialout pi
This give your pi user access to the serial port
10. Add this as 55-odd.rules to /etc/udev/rules.d/
KERNEL=="ttyACM0", SYMLINK+="ttyS7"
I needed this to ‘see’ the USB port. Before, it just didn’t show up.
If you now connect the Arduino with the sketch still uploaded to it, you can test to see if the data is coming in, by running Python from the SSH commandline:
1. type python and press ENTER
2. after the >>> type:
2.a. import serial
2.b. ser = serial.Serial(‘/dev/ttyACM0’, 9600)
2.c. while 1 :
2.c. ser.readline()
Make sure you use a 4 space indentation for 2.c.
Press ENTER twice afterwards.
If all goes as planned you will start seeing the same output as in the Arduino IDE.
Setting up the webinterface
Still not satisfied? No, of course not. Because I didn’t want that data in a SSH-session, but in a browser window.
Now, my problem was that I still know very little about Python, and in particular Python in combination with the Apache webserver (which I already had installed on the Raspberry Pi). Luckily for me, Karl McAuley has described how to setup a Python environment in combination with the Apache webserver. You can read about it here.
The steps:
1. login to the Raspberry Pi using SSH
2. type: sudo Bash to get root access
3. type: apt-get update
4. type: apt-get upgrade
5. type: apt-get install apache2 libapache2-mod-wsgi python-setuptools python-flask
6. type: usermod -a -G dialout www-data
7. edit the virtual host in /etc/apache2/sites-enabled, see the needed code changes here.
8. type: a2enmod wsgi
9. type: /etc/init.d/apache2 restart
This now restarts apache2 and you should be good to go.
Version 1
I used the myinfo.py code on Karl’s page to test the setup and then adapted the second example on his page to create code for the first version of my webpage.
You can download the code here.
OK, it works, but does not look great. There are a number of improvements that could be made. The data collected could be stored in a database so that you can create charts displaying the temperature and humidity change during the day. But the least I could do is make it look a bit prettier.
Version 2
I wanted the temperature and humidity to be displayed in a nice gauge. I found a Javascript library that looked just right for the job.
I changed the Python code so that, when I add
?json=1
to the URL, the page returns the temperature and humidity in JSON format:If you leave the “json=1” part out, the page will simply display two gauges:
The page with the gauges uses JQuery to retrieve the JSON code and the sets the gauges. The reason for this two-step approach is that it now is easy to have the page load the current humidity and temperature say every 10 seconds. Because that is all done using Javascript, the user doesn’t see the page being reloaded (because it isn’t), he would just see the gauges change if humidity or temperature changes.
Note: I haven’t added that part of the code yet, you can download the current code here.
What is next?
I think a possible next step would be to have look at the code needed to send data over the serial line to the Arduino and have it do stuff based on that. Dr. Monk has done that before but he only received single letters.
I do have all the parts to do this:
But of course, unlike there, I would set it up using the Arduino linked to the Raspberry Pi. The setup is described here. Others have described how to read data from the serial line, so that should also be doable.
Something like a webpage where you can enter a message which is then displayed on the LCD screen attached to the Arduino would be funny. Or maybe just the current Power level of the Solar Power system. We’ll see. To be continued.
This article will concentrate on the following aspects of BLDC motor design:
BLDC motors have many similarities to AC induction motors and brushed DC motors in terms of construction and working principles respectively. Like all other motors, BLDC motors also have a rotor and a stator. Stator
Similar to an Induction AC motor, the BLDC motor stator is made out of laminated steel stacked up to carry the windings. Windings in a stator can be arranged in two patterns; i.e. a star pattern (Y) or delta pattern (∆). The major difference between the two patterns is that the Y pattern gives high torque at low RPM and the ∆ pattern gives low torque at low RPM. This is because in the ∆ configuration, half of the voltage is applied across the winding that is not driven, thus increasing losses and, in turn, efficiency and torque.
Rotor
The rotor of a typical BLDC motor is made out of permanent magnets. Depending upon the application requirements, the number of poles in the rotor may vary. Increasing the number of poles does give better torque but at the cost of reducing the maximum possible speed.
Working Principles and Operation
The underlying principles for the working of a BLDC motor are the same as for a brushed DC motor; i.e., internal shaft position feedback. In case of a brushed DC motor, feedback is implemented using a mechanical commutator and brushes. With a in BLDC motor, it is achieved using multiple feedback sensors. The most commonly used sensors are hall sensors and optical encoders.
Note: Hall sensors work on the hall-effect principle that when a current-carrying conductor is exposed to the magnetic field, charge carriers experience a force based on the voltage developed across the two sides of the conductor.
If the direction of the magnetic field is reversed, the voltage developed will reverse as well. For Hall-effect sensors used in BLDC motors, whenever rotor magnetic poles (N or S) pass near the hall sensor, they generate a HIGH or LOW level signal, which can be used to determine the position of the shaft.
In a commutation system – one that is based on the position of the motor identified using feedback sensors – two of the three electrical windings are energized at a time as shown in figure 4.
In figure 4 (A), the GREEN winding labeled “001” is energized as the NORTH pole and the BLUE winding labeled as “010” is energized as the SOUTH pole. Because of this excitation, the SOUTH pole of the rotor aligns with the GREEN winding and the NORTH pole aligns with the RED winding labeled “100”. In order to move the rotor, the “RED” and “BLUE” windings are energized in the direction shown in figure 4(B). This causes the RED winding to become the NORTH pole and the BLUE winding to become the SOUTH pole. This shifting of the magnetic field in the stator produces torque because of the development of repulsion (Red winding – NORTH-NORTH alignment) and attraction forces (BLUE winding – NORTH-SOUTH alignment), which moves the rotor in the clockwise direction.