NodeMCUs

Hi!

Has anyone used NodeMCUs before? I’m trying to get 2 force sensors to wirelessly communicate to 2 servos. (x2 NodeMCUs, each with their own force sensor, talking to one NodeMCU with servo driver and 2 servos) I have all of the code, and the circuits hooked up, but they are still not connecting, and I feel like I’m just missing something small. Any help would be greatly appreciated!

Thanks,
Dani

0

1 Like

ATTN: @courty

1 Like

I’ve used these a bit, my memory sponsored by @courty is that these guys are super sensitive on the 5v line. Need very heavily regulating

1 Like

They use a stupid amount of current in a very spikey way if memory serves me right

1000uF decoupling cap ?

1 Like

Hi Dani,

without seeing your code and your circuit diagram it is impossible to say where the problem is.

What do you mean by ‘they are not connecting’? Do you mean that you cannot establish a wireless connection between the devices? Can you see any data coming form your sensors?

What I know is that the earlier versions of the model of NodeMcu you have in the picture have a limited tolerance on the analog input of just 1V. So if your force sensors have an analogue output you need to make sure to scale/divide the voltage properly. There are other ESP8266 breakout boards that allow 3.3V on the analog input.

Generally avoid 5V with these boards. They function with 3.3V.

Here is a post that explains how to divide the voltage on your analog input in case you need it. You just need to replace the potentiometer with your force sensor. And power it with 3.3V from the board.

What voltage are you giving to your force sensors?

I have controlled servos many times with those boards (even without servo drivers) and never had any problems. Are you using a separate power source for your servos?

What are you using to program your boards? Arduino IDE?

Michele

1 Like

Hi Michele,

Thanks for the help, these are very new to me and I feel a bit out my depth!

I’m using these: https://shop.pimoroni.com/products/nodemcu-v2-lua-based-esp8266-development-kit#description

With this circuit

It would be great to avoid using the servo drivers if possible, as size is a factor. Yes I’m using Arduino.

Any help would be greatly appreciated!

Thanks,
Dani

1 Like

Hi Dani,

first thing to be said, I like Pimoroni and I bought stuff from their website in the past… but those boards are really overpriced! See here or here

Regarding your circuit, I would connect your power in a different way. The Vin pin is the input to the onboard voltage regulator. Your board would say what is the max voltage you can apply. Normally 10V. The regulator then regulates down to 3.3V for the board to function. That’s why you can supply 5V at the micro USB port and your board will not fry. When you connect a USB cable, you can access the 5V supply from the Vin pin. Essentially you can connect up to (probably) 10V to your Vin pin to power your board and the regulator would do the rest.

Now the 3.3V pins on your board, are the output from the voltage regulator and give you a nice 3.3V regulated voltage from whatever you connected at the Vin pin.

So basically in your circuit the power flow is ‘reversed’. By connecting your battery straight to your 3.3V pins, you are essentially applying up to 4.2V (when battery is fully charged) to the OUTPUT of your regulator! I am not sure but you could actually damage the board this way!

Also, you are feeding the sensors more than 3.3V, meaning that if you get max output form them, you are plugging up to 4.2V into your D4 pins and you could fry them!

What I would do, is to check the minimum voltage you can plug into your nodeMCU board. If 3.7V is an option, I would connect that to your Vin pin and then power the sensors from the 3.3V pins.

if you need 5V minimum, I would use a 5V battery to power your boards from the Vin pins.

Hope this makes sense. So in general, the Vin pin is used to power the boards and it is the input to the on board voltage regulator. You shouldn’t power the sensors or the driver from that pin.

On the servos side, same thing. Turn things round. You can actually ditch the 3.7V battery there. You can plug the 5V battery to the power rail of your breadboard. From there you can power the nodemcu, the servos and the the driver.

You can also not use the driver. You can use the standard Servo library and PWM. Just make sure you power the servos straight from the 5V battery and NOT from the nodemcu itself. Connect the servo power to 5V and ground on the rail and the signal (yellow) cables to one for the digital pins. You will then tell the servo library to use that pin to control the servo.
However, you may run into a problem: the servos are powered at 5V, your control signal would be 3.3V. Your servos could actually then malfunction. Start with the driver and see if distributing the power better helps.

In the example, the servo is connected straight to the arduino. You need to connect the servo to the battery instead and make sure you connect the ground of the nodemcu to the same ground on the power rail (where the battery is connected).

If you want to keep the driver and already have the code for it, you can keep the 5V battery and power the Vin pin on the nodemcu, the V+ pin on the driver and the servos. You can then use the 3.3V pin on the nodemcu to power the driver on the Vcc pin. Connect all grounds together on the power rail.

Hope this makes sense, if you send me your code I can also have a look at it.

How are you connecting the boards on the network? Do you have an external WiFi network? Are you using a client/server structure?

Michele

2 Likes

Hi,
I normally power my NodeMCUs via Vin pin. AFAIK 3.3V labelled pins can then power other devices if need be so I suggest on the 3 NodeMCUs in your diagram, you wire 3.7v from LiPo batteries to Vin pins, then use 3.3v pins to power your additional devices.
Good luck!
Daniel
PS I have driven servos straight from NodeMCU. Only catch was that pin0 did not work and i ended up using pin1. github.com/dsikar/IOT-Trike/blob/master/IOT-Trike/IOT-Trike.ino

1 Like

Thanks!

Hi Michele,

Thanks so much! I will make those changes.

If you have a moment to look though my code that would be awesome.

IoT18_V2.zip (898.9 KB)

Thanks,
Dani

@MichelePanegrossi the serial monitor for the client is saying:

Not found: /Pres/
closing connection
Analog reading = 5
1
connecting to 192.168.4.1
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 17
Connection: close

@MichelePanegrossi
But when I reset the client with the serial monitor open, with the servoserver off and then turn it back on, it says this:


WiFi connected
IP address:
192.168.4.2
Analog reading = 6
1
connecting to 192.168.4.1
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 17
Connection: close

Not found: /Pres/
closing connection
Analog reading = 5
1
connecting to 192.168.4.1
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 17
Connection: close

@Dani_Clode ,
I’m looking at your code and doesn’t look like you are calling handleRoot anywhere in the serverServo file .

Hi Guys,

Appols, been v busy at work and have just seen this.

As you can see from the above there is a bit of an art to getting the boards to behave but once running they are normally rock solid. Great pieces of kit.

Are you around tonight @Dani_Clode ?
Happy to have a play and debug the electronics and code. Much easier face to face

Courty

To be honest I would expect your code to work.

I can see you are calling server.on("/Pres", handleGenericArgs);
So you are not trying to call handleRoot() at all, but call handleGenericArgs() instead which is fine I think.

I am sorry I don’t have nodeMCU boards at hand. I can test your code on Sat and let you know if you can wait until then.

Things you could try in the meantime:

  • Connect your computer to the ESP network. Open a browser and try getting the ESP server to react. You could type something like “192.168.4.1:80/Pres/?1f=500” and see what you get in return.
  • You could get rid of the /Pres argument all together. You could try server.on("/", handleGenericArgs) and see if that helps.
  • What happens if you try “192.168.4.1:80/Pres” ? What do you get in your browser?

In your for cycle inside the handleGenericArgs() function, can you print the args the server receives? That way you will know how it is actually interpreting what it receives from the clients.

You don’t seem to get a “connection failed” reply in your clients serial monitor which means they can see the server. But it seems like they request something the server doesn’t have hence the 404 reply. However, there is no explicit handling of the “not found” reply therefore it must be in the actual libraries somewhere.

Let me know if any of the tests above produce a result!

Michele

1 Like

@MichelePanegrossi thanks! I’m in Saturday afternoon if you’re around.

Thanks,
Dani

@Courty Yes I’m in this afternoon if you’re around?

Your code worked for me changing in ClientPressureSensor_b.ino

client.print(String("GET ") +"/Pres/?1f="+forceValue+" HTTP/1.1\r\n" +

for this

client.print(String("GET ") +"/Pres?1f="+forceValue+" HTTP/1.1\r\n" +

There are some other suggested changes here:
https://github.com/dsikar/pressure-sensor

Noting ClientPressureSensor2_b.ino has not been tweeked.

Good luck! :slight_smile:

1 Like

@dsikar thank you so much! They are connecting now:

Number of args received:1
Arg n0–> 1f: 0

closing connection
Analog reading = 2
0
connecting to 192.168.4.1
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 43
Connection: close

But the servos aren’t responding to the pressure sensors

1 Like

Hi Dani,

First, one question. In your circuit diagram, the force sensors are connect to pin D4. However, in the code you read from the analog pin. Have you connected your force sensors to A0 now?

What’s happening is probably that you are sending the wrong range of values to the setPWM function.

Look at what you just posted:
Arg n0–> 1f: 0

closing connection
Analog reading = 2
0
connecting to 192.168.4.1

This means that your analog read from the sensor is only ‘2’! Which is saved in your ‘fsrReading’ variable.

After that, it goes through the map function
forceValue= String(map(fsrReading, 0, 1023, 0, 255));

the result is 0.49 which is somewhere converted to a ‘0’!!

In your serial monitor you have
Analog reading = 2
0

That 0 is the result of the map funciton.

So essentially you are calling your setPWM function with all zero values!!

pwm.setPWM(0, 0, argVal.toInt());///first number represents the servo number

as argVal is in fact ‘0’.

Your servo is never going to move.

As the driver library suggests a pulse length of 150 to 600, you should make sure that your force sensors produce values in that range.

If you get values between 0 and 1023 in your analog read, you should map to a different range:
forceValue= String(map(fsrReading, 0, 1023, 0, 600));

I think you should monitor what values you are getting at the analog input pin. If they are too low or to high, you can change the resistors you are using with your force sensors to make them more or less sensitive.

Try this code on your force sensors boards and see what you get:

int sensorPin = A0;
int sensorValue = 0;

void setup() {
Serial.begin(115200);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
}

Hope this helps!

Michele

1 Like