I ordered the next bunch of stuff and started experimenting.
I’m still very unskilled in programming… i really just do simple stuff atm and try to get each module working somehow… one after another.
Actually I’m on the last Module… the io60p16 … and I somehow don’t get it working.
I wanted to make a PWM signal that I could later use to regulate a motor… but somehow I can’t use any of the features of that module.
I have it in the project added is connected to the correct socket.
Also the lines from the Developers Guide Site aren’t working (also when I correct the Capital letters thingy).
Any ideas how I can make a PWM signal or use any features at all? O.o
Maybe I do something totally wrong? >.>
Regards the examples having compilation issues due to variable names: the “namespace” in the example code must be changed to match the namespace in Program.generated.cs. see http://www.ghielectronics.com/docs/35/namespaces (this is true of many of the examples in the documentation. For example if the namespace statement in Program.generated.cs is “GadgeteerApp1” then in the example code the line “namespace change_this_to_your_namespace” in the example should be changed to “namespace GadgeteerApp1”
Ah well, I didn’t just copy the example… I always add part for part to get an understanding. but this time it doesn’t work.
the example line io60p16.PWM pwm1; is unknown in that part of the programm.
Also in the initialisation methode is just io60p16 kown… but it was no options to use…
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
namespace PWM_test1
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
io60p16.PWM pwm1; // io60p16 is Unknown here
void ProgramStarted()
{
Debug.Print("Program Started");
io60p16. // -------------- No Options aviable here------------
button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
}
void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
//throw new NotImplementedException();
}
}
}
since it doean’t know any features of the io60p16 is it also not possible to use .PWM() … or anything else like in the example
Debug.Print("Program Started");
// -------------- No Options aviable here------------
pwm1 new io60p16.PWM(io60p16, io60p16.PWMPin.PWM1, io60p16.PWM.TickWidth.TickWidth_Servo_23438hz_42666ns);
ahhh kay. so it’s this time a class that I use…
should this class be in the Gadgeteer library or do I have to mage that by my own?
If it try to initialisite th class, it says that it doean’t know this class.
namespace PWM_test1
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
IO60P16.PWM pwm1; // IO60P6 is Unknown here
void ProgramStarted()
{
Hi Evul, can you tell us what mainboard you’re using, and what Visual Studio version you’re using?
Here’s how I did what you are attempting to do.
Created a new Gadgeteer project, my Cerberus mainboard was on the design surface, I dragged a IO60 module onto the design surface, named it “myio60”, and auto-connected it. Jumped over to the program.cs.
Then, started typing:
GTM.GHIElectronics.IO60P16.OutputPort p1 = new GTM.GHIElectronics.IO60P16.OutputPort(myio60, GTM.GHIElectronics.IO60P16.IOPin.Port0_Pin0, true);
or for PWM:
GTM.GHIElectronics.IO60P16.PWM pwm1 = new GTM.GHIElectronics.IO60P16.PWM(myio60, GTM.GHIElectronics.IO60P16.PWMPin.PWM1, GTM.GHIElectronics.IO60P16.PWM.TickWidth.TickWidth_Servo_23438hz_42666ns);
Hopefully that can show you what you need to do?
edit: Jeff, the developers guide is what is misleading here I think, if there was an extra “using” somewhere to shortcut to GTM.GHIElectronics it would work…
This is about the scope of the object you’re creating. Time to learn that
Because you create the pin in the button handler, as soon as the button handler exits that object is out of reference and can be garbage collected.
What I would do. Start with a Boolean object and a PWM object in your program class. In the button press handler, then you can check the Boolean - if it’s set whatever way you choose, you create the PWM object and it should then run, but if the Boolean is opposite then you dispose the object, of course you need to reverse the Boolean flag in both cases. This means the button becomes a toggle, and should stop the “re-use” issue which is what I suspect caused your error, a 2nd button press. But whether that actually stops the PWM I don’t know; I guess testing should show you
But probably I see this waaaaay to easy and they way is much more complicated^^
my try:
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
Boolean Toggle = false;
void ProgramStarted()
{
Debug.Print("Start");
GTM.GHIElectronics.IO60P16.PWM pwm1 = new GTM.GHIElectronics.IO60P16.PWM(myio60, GTM.GHIElectronics.IO60P16.PWMPin.PWM1, GTM.GHIElectronics.IO60P16.PWM.TickWidth.TickWidth_Servo_23438hz_42666ns);
button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
}
void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
Debug.Print("button pressed");
Toggle =! Toggle;
Debug.Print("Toggle: " + Toggle);
if (Toggle == true)
{
//activate the PWM signal here... somehow
}
else
{
//deactivate the PWM again.... somehow >.<
}
}
}
If possible I’d like to avoid to buy a PulseInOut Module… since shipping and customs duty is veeeery expensive >.<
The L298 module works with pwm too (althought it’s a horrible signal) but that one is easy to handle… I’d wish that the io60p16 module would have such easy functions to use pwn >.<