Go Down

Topic: Problem with Arduino Esplora pins (Read 583 times) previous topic - next topic

nicolopadovandev

#15
Jan 09, 2019, 01:47 pm Last Edit: Jan 09, 2019, 01:52 pm by nicolopadovandev
How do I use the library? I installed it and included it.
I'm trying to make the 14, 15, 16 (the first 3 pins in the purple boxes that we mentioned) be like the arduino UNO's pins, but I don't understand how
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

The library comes with a simple usage example you can open at File > Examples > PalatisSoftPWM > PalatisSoftPWM_example.

What you need to do is define 3 channels, each of which is assigned an Arduino pin. Then in your code, you will control the PWM on each of those pins by referring to the channel numbers. In the example, only one channel is defined, on pin 13:
Code: [Select]
SOFTPWM_DEFINE_PIN13_CHANNEL(0);

You can refer to the documentation for detailed information on any of the libraries functions:
https://github.com/per1234/PalatisSoftPWM/blob/master/README.md

nicolopadovandev

#17
Jan 09, 2019, 02:06 pm Last Edit: Jan 09, 2019, 02:08 pm by nicolopadovandev
SOFTPWM_DEFINE_PIN14_CHANNEL(0);
SOFTPWM_DEFINE_PIN15_CHANNEL(1);
SOFTPWM_DEFINE_PIN16_CHANNEL(2);
SOFTPWM_DEFINE_OBJECT(3);
const int controlPin1 = 0;
const int controlPin2 = 1;
const int enablePin = 2;


Now if I do
analogWrite(enablePin, HIGH);

the motor should run, correct?
Also in the setup() i've put the PalatisSoftPWM.begin(255); command
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

SOFTPWM_DEFINE_PIN14_CHANNEL(0);
SOFTPWM_DEFINE_PIN15_CHANNEL(1);
SOFTPWM_DEFINE_PIN16_CHANNEL(2);
SOFTPWM_DEFINE_OBJECT(3);
Perfect!
const int enablePin = 2;
Are you sure you need PWM on the enable pin? When I think of an enable pin, I expect it to only need to be set HIGH or LOW using digitalWrite depending on whether I want to enable or disable the motor.

Now if I do
analogWrite(enablePin, HIGH);

the motor should run, correct?
analogWrite is only for hardware PWM. When using the PalatisSoftPWM library, it would look something like this:
Code: [Select]
PalatisSoftPWM.set(enablePin, 255);
Also, it doesn't make sense to use HIGH with analogWrite. HIGH is to use with digitalWrite. analogWrite takes a value 0-255.

nicolopadovandev

Yep sorry i need the motor to get different speeds so i need PWM. For the other two pins I can use the digitalWrite bc i need them to be only HIGH or LOW. Can I use the pins as they are by default on the board?

I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

If you only need to do PWM on one pin then there is no need to use software PWM. You can use one of the two hardware PWM pins from the TinkerKit connectors and use any of the other pins for the non-PWM outputs.

nicolopadovandev

#21
Jan 09, 2019, 02:32 pm Last Edit: Jan 09, 2019, 11:38 pm by Coding Badly
I connected three LEDs on the board and created this code:

Code: [Select]

#include <Esplora.h>
#define SOFTPWM_OUTPUT_DELAY
#include <PalatisSoftPWM.h>
SOFTPWM_DEFINE_PIN16_CHANNEL(16);
const int ledPin = 14;
const int ledPin2 = 15;
const int ledPin3 = 16;

SOFTPWM_DEFINE_OBJECT(1);
void setup() {
  PalatisSoftPWM.begin(255);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  PalatisSoftPWM.set(ledPin3, 250);
}

void loop() {
  int switchState = !Esplora.readButton(SWITCH_1);

  if(switchState == HIGH){
    Esplora.writeGreen(255);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, HIGH);
    PalatisSoftPWM.set(ledPin3, 250);
  } else {
    Esplora.writeGreen(0);
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2, LOW);
    PalatisSoftPWM.set(ledPin3, 0);
  }

}


The first 2 LEDs work, but the one with the PWM (which should be on with less light than the other two) doesn't. What do I have to do?
The one that doesn't is the one connected to the library obviously

Moderator edit: [code] [/code] tags added.
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar, then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.


Code: [Select]
SOFTPWM_DEFINE_PIN16_CHANNEL(16);
The parameter is the channel number. The first channel should be 0:
Code: [Select]
SOFTPWM_DEFINE_PIN16_CHANNEL(0);
Then you need to update your PalatisSoftPWM.set() calls to use 0 as the channel parameter, rather than 16. After making that change, the PWM should work.

pert

From the other thread:
http://forum.arduino.cc/index.php?topic=589763.msg4011590#msg4011590
Quote
I was searching for a way to transform the normal pins (so not the tinker kit ones) into ppm pins because I don't have an adapter for the tinker kit
I've never looked at this connector in real life, but there's a good chance you could put female dupont connectors on the pins. Dupont connectors are the ones on the jumper wires you use with breadboards. They come in both male and female versions:

Those are a very useful thing to have on hand regardless.

nicolopadovandev

Thank yiu, tomorrow I'll try with the code that u told me. Where can I buy those wires?
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

I'm a cheapskate so I buy my jumper wires on Aliexpress or eBay and wait for the long shipping from China. You can find them pretty much anywhere that sells electronics components (Amazon, Sparkfun, Adafruit, Seeed, Digikey, Arrow, Mouser, RS, Newark, etc.). I have a box of them in every configuration: male-male, male-female, female-female.

nicolopadovandev

I'm about to try the code that u sent me.
Can u please help me even on this discussion? https://forum.arduino.cc/index.php?topic=589841.0
It's about something completely different from the things that we are discussing here
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

nicolopadovandev

IT WORKED!!! I LOVE YOU!!! UAAAAA I CAN'T EXPLAIN TO YOU HOW MUCH I'M HAPPY RIGHT NOW, I TRIED FOR TWO DAYS!!! Now pleeeeease help me on the other discussion xoxoxoxo
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

nicolopadovandev

is it possible that these libraries can be in conflict between each other? Because if i adds Servo.h it gives me an error...

#include <Esplora.h>
#define SOFTPWM_OUTPUT_DELAY
#include <PalatisSoftPWM.h>
#include <Servo.h>
I'm just trying to send a rocket controlled by arduino to the space and back. Hi Elon Musk.

pert

IT WORKED!!! I LOVE YOU!!! UAAAAA I CAN'T EXPLAIN TO YOU HOW MUCH I'M HAPPY RIGHT NOW, I TRIED FOR TWO DAYS!!! Now pleeeeease help me on the other discussion xoxoxoxo
I'm glad to hear it's working.

Now pleeeeease help me on the other discussion xoxoxoxo
I'll try to get to that soon. And you're correct that it's a separate topic that is appropriate to have its own thread.

is it possible that these libraries can be in conflict between each other? Because if i adds Servo.h it gives me an error...

#include <Esplora.h>
#define SOFTPWM_OUTPUT_DELAY
#include <PalatisSoftPWM.h>
#include <Servo.h>
When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar).

Go Up