Also, not super important but certainly a useful tidbit-- Particle.function
works as well as Spark.function
and the two can be used relatively interchangeably.
I just gave a presentation at the CUEBC conference in Vancouver. I sat in on some LEGO, VEX and Arduino presentations. Now more convinced than ever about how useful the Photon will be in the classroom. I am going to do some research on sensors and try to get some examples of using various sensors with the Photon. I am going to look at what sensors can be added to the Photon Maker Kit documentation here
So here is my next issue, which I gave it's own topic.
Just finished working on an simple AJAX Get webpage for Particle.variables using strings at
I just used a similar AJAX webpage to the one in the above post to extract all the live sensor information from the IP Camera for Androiid. This could be helpful with Phonegap to make Apps for your Particle.io device. Basically the Photon could interact with your live streaming cell phone sensor information.
Note: The IP Camera allows access to the following sensors: proximity, rot_vector, gravity, battery_temp, light, battery_level, gyro, accel,lin_accel, pressure, battery_voltage, mag. Which seriously reduces the amount of sensors you have to purchase for your Photon.
See github at
Been doing some work with IFTTT. see the link at
and at
Latest thing working is both Cloud9 and the Particle.io CLI and a simple example of using webhooks
Really enjoying using:
Particle.publish("Log-this-to-google-drive", data, 60, PRIVATE);
Particle.publish("Log-this-to-google-drive", String(myInt), 60, PRIVATE);
Particle.publish("Log-this-to-google-drive", String(myFloat), 60, PRIVATE);
anywhere in my code and monitoring it live over wifi by opening the google document in google drive. Great for debugging the things that most people would use serial.print() for. You would still have to use serial.print for high speed results, but for regular debugging, the above commands are great. They take about 2 seconds to show up and can be used several times in your code.
Also debugging a Wifi device by hooking it up to a computer using a USB cable seems hypocritical, whereas this technique is fully Wifi compatible.
Lots of tutorials out there on how to use IFTTT, but here is the easy version:
basically leave most things as default or blank
- login IFTTT
- click “My Recipes”
- click “Create a Recipe”
- click “This”
- choose Trigger Channel type “particle”
- login to particle (only have to do this once)
- click “new event published”
- If (Event Name) enter “Log-this-to-google-drive” (The name you published)
- Is (Event Contents) Leave this blank (Took a while to learn that trick)
- Device name or ID, Select your photon from the pull-down list
- Click “Create Trigger”
- Click “That”
- Choose Action Channel, Type Drive, select google drive, (Only have to login once)
- Click “Append To Document”
- Leave everything default and click “Create Action”
- Finally Click “Create Recipe”
It looks like a lot of steps but it is fairly mindless once you have done it. Open up google drive and look for a new folder called “events” Inside that folder should be a file called “Log-this-to-google-drive”
Every once in a while I delete the entire contents of the google docs file so that I can see what is the new stuff being written. The really great thing is that on that Photon you can now just include the line:
Particle.publish("Log-this-to-google-drive", data, 60, PRIVATE);
anywhere in future versions of your code and it will still log the variable “data” to IFTTT without any more work on your part.
Here is a screenshot of the final IFTTT Recipe
P.S. There is another little IFTTT trigger that lets you monitor if your photon is on or off (The “off” takes several minutes to log, but the “on” is very fast about 2 seconds). The “On” feature is really useful when debugging your Photon to prove that the Photon is communicating with Google Drive. The following image shows the “Monitor your device status” trigger circled in red whereas the trigger for the above recipe is in yellow.
While my Robotics class is waiting for sensors to arrive, I am looking into Neural Networks using the Photon at
Just got my class sets (15 each) of Pololu: DC motors, Stepper Motors and Servos. Hopefully test tomorrow if the following code works. It should allow each pair of students to work all three types of motors using one photon
For the code to work students will need to power D6 with a switch from 3V3. The motor hookups should be obvious from the code.
NOTE: The DC motor should use a motor driver such as the one I us below. Can someone correct me if I am wrong but both the Servo and Stepper motors need a separate 5V supply (best not to use VIN, since you would have to monitor total current used and possibly hurt the photon). The control cables for both the Servo and Stepper Motors can be connected directly to the photon.
Anyone want to give an opinion about protective capacitors hooked up to the motors.
.
.
.
.
// EXAMPLE CODE
// warning all these motors need 5V power from a seperate 5V sorce.
// Will also need a motor driver to use them.
// You can test one motor at a time
Servo myServo; // create servo object to control a servo
// a maximum of eight servo objects can be created
void setup()
{
pinMode(D7, OUTPUT);
pinMode(D6, INPUT_PULLDOWN);
pinMode(D5, OUTPUT); // this is for the DC motor Direction
pinMode(A5, OUTPUT); // This is for the DC motor speed (PWM see above)
myServo.attach(A4); // attaches the servo on the A4 pin to the servo object
// Use the pins that has PWM on the Photon : A4, A5, WKP, RX, TX, D0, D1, D2, D3
pinMode(D0, OUTPUT); // stepper motors need 4 digital PINS
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
}
void loop()
{
digitalWrite(D7, 0); // turn D7 LED off
delay(300); // dealy 300 ms to see the LED flash off
if (digitalRead(D6) == 1){ // test if D6 has power
digitalWrite(D7,1); // if D6 has power turn D7 back on.
// for accuracy use servo.writeMicroseconds(1500); uses a range from about 700 - 2300 test your servo
myServo.write(0); // tell servo to go to position 0 (check is it 0 - 180??)
delay(300); // waits 100ms for the servo to reach the position
myServo.write(90);
delay(300);
myServo.write(180); // 180 degrees
delay(300);
myServo.write(90);
delay(300);
myServo.write(0);
delay(300);
// Now test the DC motor
digitalWrite(D5, 0); // sets the motor direction lets call it counterclockwise
analogWrite(A5, 0); // A5 is PWM range 0-255, motor speed
delay(300);
analogWrite(A5, 50);
delay(300);
analogWrite(A5, 255);
delay(300);
analogWrite(A5, 100);
delay(300);
analogWrite(A5, 0);
delay(300);
digitalWrite(D5, 1); // now set the DC motor to clockwise. Depends on the wires
analogWrite(A5, 50);
delay(300);
analogWrite(A5, 255);
delay(300);
analogWrite(A5, 0);
delay(300);
// Now try a stepper motor
myStepClockwise(300); // longer delay slower
myStepClockwise(300);
myStepClockwise(100);
myStepClockwise(100);
myStepClockwise(20);
myStepClockwise(20); // shorter delay faster
myStepStop(); // make sure no power going to Stepper
// Now this procedure repeats forever as long as D6 has power
}
}
void myStepClockwise(int myDelay){
digitalWrite(D0,1); //power D0
digitalWrite(D1,0);
digitalWrite(D2,0);
digitalWrite(D3,0);
delay(myDelay);
digitalWrite(D0,0);
digitalWrite(D1,0);
digitalWrite(D2,1); //power D2
digitalWrite(D3,0);
delay(myDelay);
digitalWrite(D0,1); //power D0 inverse
digitalWrite(D1,1);
digitalWrite(D2,0);
digitalWrite(D3,0);
delay(myDelay);
digitalWrite(D0,0);
digitalWrite(D1,0);
digitalWrite(D2,1); //power D2 inverse
digitalWrite(D3,1);
delay(myDelay);
}
void myStepStop(){
digitalWrite(D0,0);
digitalWrite(D1,0);
digitalWrite(D2,0);
digitalWrite(D3,0);
}
.
.
.
.
.
I will try to use the Pololu dual motor driver DRV8835 https://www.pololu.com/product/2135 for the DC motor.
@rocksetta, you are correct in you statement that the servo and stepper motors should be powered from a separate supply and not through Vin. The Photon has a reverse polarity diode on Vin which is rated for 3A but potential current spikes in the motors can exceed that.
The Pololu motor controller provides isolation between the Photon logic (3.3v) and the motor voltage so you will be fine there. Besides the overheating cautions for the Pololu board, you don’t need any other protection for the motors since that’s handled by the DRV8835. However, the motor power supply needs to be able to handle the total motor current requirements.
I am good with the Servo and DC Motor, but my stepper is confusing me a bit. It is fairly small, only 3.9 V and 600 mA. https://www.pololu.com/product/1204
I may have incorrectly assumed my dual motor driver https://www.pololu.com/product/2135 would work with it, but have not found any examples of connection methods, it seems to be only for DC motors. I was planning on using D0, D1, D2, D3 to control the stepper as per program above. I could use a transistor to step-up the current and voltage or purchase a Stepper Motor driver such as https://www.pololu.com/product/1182 which looks easy enough to control with direction and step from the photon digitalWrite. Any opinions about the best method for now?
On second thoughts, if I change my software in the above program can’t I hack my dual motor driver with something like the following diagram??? Instead of PWM, DO and D2 would be either High or Low. D1 and D3 determine the direction of flow through the motor. Then I only need to figure out how to program it so that the current flows at the right time in the right direction in the right order. Opinions Please.
@rocksetta, perhaps the best goof-proof approach, especially with students is to get the Pololu low voltage stepper motor driver:
No fuss, no muss!
I agree as the stepper motor driver only takes 2 digital pins to control, instead of the above 4 pins. I will look for one that allows higher amps so that we can control larger stepper motors (Some students want to make robot hands etc), but for the present moment, looks like my DC motor driver hack works (Got a really capable student to figure it out:>).
The only problem is that the Servo motor only works on the first loop? I reset the photon and it works again, but for more loops the other motors work fine but the servo does not.
Any suggestions, other than my really bad choice for a power supply (4 AA batteries for all three motors, since they never run at the same time.). I thought maybe the Stepper was still live but I included a stop function.
By the way my DC motor (with attached protective capacitor across it’s leads) is https://www.pololu.com/product/3225 and my servo motor is https://www.pololu.com/product/1057
You can see a very messy wiring job video on my twitter feed at https://twitter.com/rocksetta
Oops, my Bad. No common ground for the Servo. Somehow it found a ground for the first loop. Might be more complex since that was just on my debugging run.
I have an uncanny ability to try things that find issues. For the above program the servo on A4 PWM works fine as long as the DC motor is not running on A5 PWM . If the DC motor PWM channel is switched to TX, RX, or WKP Everything (all three motors) work fine. If the DC motor is on A5 PWM, the servo works once then only after a power reset.
In the reference on https://docs.particle.io/reference/firmware/photon/#analogwrite-
Which states:
On the Photon, this function works on pins D0, D1, D2, D3, A4, A5, WKP, RX and TX with a caveat: PWM timer peripheral is duplicated on two pins (A5/D2) and (A4/D3) for 7 total independent PWM outputs. For example: PWM may be used on A5 while D2 is used as a GPIO, or D2 as a PWM while A5 is used as an analog input. However A5 and D2 cannot be used as independently controlled PWM outputs at the same time.
Thought Particle should know about the issue. I am running GPIO pins on D0, D1, D2, D3.
So here is a picture of our flexy-hand (Thingiverse http://www.thingiverse.com/thing:242639) The main parts are printed with PLA but the flexible connectors are printed with Ninjaflex (semi-flex).
Note: I connected the smallest two fingers to one servo to make it easier.
It works using a webpage turned into Android App (Phonegap build) and individual motors for each servo. As per above comment, I would really like to see 7 servo’s working with the Photon. I had to do a ton of playing around and eventually settled on D1, D2, RX, TX. I will play around a bit more, but it was really confusing.
Theoretically both these setups for 7 servo’s should work:
D0, D1, A4, A5, WKP, RX, TX
or
D0, D1, D2, D3, WKP, RX, TX
but from my experience it is a bit more confusing. I will have to try all seven and see what the issue is.
My sensor parts just came in from http://www.Robotshop.ca
I Wrote some easy code to use an ultrasonic range finder
Today we got the moisture sensor and muscle sensors working, both were fairly easy.
The best thing about the Particle Client (CLI) is that you can get easy serial println information for testing your code. Most example programs use serial.println("Something Really Important"); Unfortunately in a school setting the computers tend to be locked down and installing software can range from supper easy (Chrome) to ridiculously difficult since the computer PATH is normally out of reach. You can always wait for a tech to install the software for you (Still waiting for them to install this new browser called Netscape ), but then you have little ability to tweak it or update the software.
My solution has always been to flash code that communicates using the D7 LED, but as my abilities get better, I am finding that a serial connection would be better.
One of my students was loading an example arduino code on a Mega and it used an Android App to read the serial output. That made me think how much more useful that would be in the classroom setting. So I made this Thread
And then I thought wouldn't it be great to be able to control the photon over Wifi and over a connected Android App. So later on in the above thread I got that going at USB Android Serial - #4 by rocksetta the github site is at
I need to tidy up that github site and hopefully will not break it. It uses phonegap to convert a normal webpage into an Android AppI uses the online cloud9 to fully set up a development workspace with the Android-SDK.
Flex sensor example at