arduino, ESP8266

Turns out autonomous vehicles can be complicated :-)

Here you have some sample code for a ESP3866 with a motor shield:

https://github.com/CrashSerious/HackerBoxes0013/blob/master/Projects/AutonomousCar/AutonomousCar.ino

And… well… this is how it runs:

Advertisements
Standard
Uncategorized

Running a 5V 5mw 650NM laser from Arduino.

Simple as shit, but as I haven’t found it….

It’s almost the same as the “blink” example from Arduino IDE. One just needs to change the pin (I use ~11), and use analog write instead of digital.

Follows the code:

int laser = 11;

void setup() {
 pinMode(laser, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
 analogWrite(laser, 20); // 20:enough. 100: hurt your eyes
 delay(1000);
 analogWrite(laser, LOW);
 delay(500); // cool it down
}

IMG_6156.JPG

Standard
Uncategorized

Robot car controlled by iPhone using Blynk and NodeMCU.

Materials:

I created a simple app on Blynk with 4 buttons connected to virtual Pins.

See how to install and run Blynk here.Then, just connect those buttons to virtual pins, like this:

IMG_4762.PNG

Forward: V0, Backwards: V1, Right: V2 and Left: V3. It look like this:

img_4756

Got a token for the project and used on the following file on your Arduino IDE.

/**************************************************************
 * This example runs directly on NodeMCU chip
 * using the Blynk platform and mobile application.
 * Change WiFi ssid, password, and Blynk auth token to run :)
 **************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define RightMotorSpeed 5
#define RightMotorDir 0
#define LeftMotorSpeed 4
#define LeftMotorDir 2

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "MyWifi";
char pass[] = "MyWifiPassword";

void setup()
{
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass);

 pinMode(RightMotorSpeed, OUTPUT);
 pinMode(RightMotorDir, OUTPUT);
 pinMode(LeftMotorSpeed, OUTPUT);
 pinMode(LeftMotorDir, OUTPUT);
}

void loop()
{
 Blynk.run();
}

void halt()
{
 digitalWrite(RightMotorSpeed, LOW);
 digitalWrite(LeftMotorSpeed, LOW);
}

void forward()
{
 digitalWrite(RightMotorDir, HIGH);
 digitalWrite(LeftMotorDir, HIGH);
 digitalWrite(RightMotorSpeed, HIGH);
 digitalWrite(LeftMotorSpeed, HIGH);
}

void reverse()
{
 digitalWrite(RightMotorDir, LOW);
 digitalWrite(LeftMotorDir, LOW);
 digitalWrite(RightMotorSpeed, HIGH);
 digitalWrite(LeftMotorSpeed, HIGH);
}

void right()
{
 digitalWrite(RightMotorDir, LOW);
 digitalWrite(LeftMotorDir, HIGH);
 digitalWrite(RightMotorSpeed, HIGH);
 digitalWrite(LeftMotorSpeed, HIGH);
}

void left()
{
 digitalWrite(RightMotorDir, HIGH);
 digitalWrite(LeftMotorDir, LOW);
 digitalWrite(RightMotorSpeed, HIGH);
 digitalWrite(LeftMotorSpeed, HIGH);
}

BLYNK_WRITE(V0)
{
 if (param[0])
 forward();
 else
 halt();
}

BLYNK_WRITE(V1)
{
 if (param[0])
 reverse();
 else
 halt();
}

BLYNK_WRITE(V2)
{
 if (param[0])
 right();
 else
 halt();
}

BLYNK_WRITE(V3)
{
 if (param[0])
 left();
 else
 halt();
}

Wiring up the shield to the engines and battery is straightforward. Left wheel is “Motor B”, right wheel is “Motor A”, and power goes to “ESP Power”. If you insert a jumper on the “shortcut” on the VIN and VM pins, it will power the NodeMCU from the same power source.

original-doit-esp8266-nodemcu-motor-shield-with-l293d-extension-board-for-rc-kit-diy-smart-car

IMG_4761.JPG

Assembling everything together, the thing comes out like this (click to zoom):

And it runs well:

Right now, this is a dumb machine. I will install some intelligence on it pretty soon 🙂 Besides, I will play with different wheel options and maybe a servo on the front.

Standard
Uncategorized

Cheap Chinese Arduino clones or Serial-to-USB with the CH340G / CH341G on MacOS Sierra

I got an Arduino UNO clone for around 3 euros on Aliexpress. It’s like 8 times cheaper than the original one, and, unlike the piece of shit that the Orange Pi is (check my previous post), the quality of this clone is the same as the original… Almost.

screen-shot-2016-11-03-at-19-52-28

An AlmostDuino 🙂 For 3 bucks instead of 25, who is complaining?

It uses the same Serial-to-USB CH340G chip that you can find on the USB-Serial module. Therefore, they are not directly supported on MacOS Sierra.

fvkpqkzitkljgsg-largeSerial-to-USB module.

If you google around, you will find a driver.. That kernel Panics MacOS. Seriously, it’s been the first kernel panic I’ve seen in YEARS on Mac OS.

Well, the driver is here: https://tzapu.com/ch340-ch341-serial-adapters-macos-sierra/ you have to reboot after that. It will appear at your Mac as a /dev/tty.wchusbserialXXXX and the Arduino will work as intended. Or the serial adapter like the one you see above. Both use the same driver.

Have fun!

Standard
Uncategorized

Orange Pi Lite and the value of communities

I am a subscriber of hackerboxes.com. It’s a great way to get into some easy projects that you would probably not do by yourself if you would have to buy everything from Aliexpress and wait 3 months for your shit to get home. It’s pretty much like hellofresh for electronics.

priorbox0010_585_350

Typical hackerboxes’ contents.

September’s box came with an Orange Pi lite – a supposedly contender on the single-board computers.

I’ve read about that before, as I read about many other single-board computers which appeared recently. They all claim to be better than the Raspberry Pi in one way or another. Or cheaper. Or both.

In fact, I have a C.H.I.P. $9 computer, and it works great – if that shit had HDMI, I would buy a dozen of them. Or…. maybe not.

C.H.I.P. – the worst name ever to google for. But it has DOGE-quality control. Seriously.

But I digress.

Why people use those single-board machines? Basically because they are cheap as fuck and because it’s so easy to use their GPIOs. Want to attach a small screen? 2 and a half bucks and a download. Pretty much everything on the Raspberry Pi is like this.

That orange pi claimed full compatibility with Raspberry Pi. Well, it does not. The GPIOs are different, the libraries are different (and not so available), the whole Linux distribution is different. In fact, it sucks to install ANYTHING on it. Reviews after review they tell how this machine sucks. How finicky it is with SD cards and power sources, how it doesn’t tell you shit before the boot, how slow it actually is, etc etc.

I remember that took me a week to make mine to boot. Then, this week, I decided to install RetroPie, a Linux distribution with emulators in mind, and play some Super Mario.

Big Mistake.

After spending hours downloading and copying the image to the SD card and not having ANY idea what the fuck was going on (the Orange Pi does not turn on the screen, a LED, nothing, until it successfully boots), I decided to go for a serial console.

Yep. I am using a serial console in 2016 because a 2016 computer can’t bother to light a fucking led when it’s on.

Interestingly, the Orange Pi’s hardware can be so great in some aspects, and suck in others. For example, it has Wi-Fi, IR, a proper reset button, it’s quad-core, etc etc. And it costs 12 bucks.

To connect the Orange Pi to my Mac, I used a USB-to-Serial (isn’t usb serial already?) CH340. This:

fvkpqkzitkljgsg-large

Welcome to 1962. Here is your RS-232 connector from a Macbook Pro to a Quad-Core computer made in 2016 for US$ 12.

The Orange Pi has 3 pins for RX, TX and GND for a serial console, which you connect to this little thing and then to the Mac. Except that you need a driver for it, and the official one makes the Mac go bananas. Really. I haven’t seen a Mac have a kernel panic in almost 10 years. But there is a fix for mac kernel panic.

After that, it’s a matter of running a

screen /dev/cu.wchusbserialXXXXXXX 115200

Where XXXXX is whatever in your computer. After that, you are able to see what this piece of crap is doing before it shows anything on the screen.

img_3848My OrangePi connected to a Mac via usb-to-serial.

After using this I somehow managed to make this crap boot. But not with the RetroPie I wanted, but with the same vanilla Armbian (Debian for arm – got it?) that I had before.

And I don’t know what to do with it.

  • It’s slow as fuck.
  • It needs its own stupid power cable. It’s the worst thing about the whole machine. Seriously.
  • It’s REALLY finicky. You tell it to reboot? Good luck! It will certainly stop responding, but sometimes it can reboot. Mostly not.
  • Setting up wifi is a real pain in the ass.
  • It overscans on my HDMI tv. Their response? Get a new TV.
  • Do I need this stupid Wi-Fi antenna? It’s slower and worse than the invisible one from the Raspberry Pi 3.
  • I can’t have ANY idea about what’s going on until the machine is in the middle of Linux boot. If it worked fine, that wouldn’t be a problem, but it does not.
  • The manufacturer does not provide even their own Linux image!
  • GPIOs totally different from Raspberry Pi. No libraries work without being adapted.
  • Community support? It exists, but it’s small and a best-effort thing for a machine whose destiny is to be forgotten.
  • If I want the nintendo emulator, I need to configure it by hand as if this is Slackware in 1994.

I was reading some forums, where some nerd said that “If you want a great machine, buy [whatever], if you want marketing, buy a Raspberry Pi”. And I was thinking about that.

To run a PWM engine on the Raspberry PI, I have to import pwm in a python program. To use an SSD1306 OLED screen, all I need to do is “import SSD1306”. And so it goes.

To find solutions about your problems, there are literally thousands of sources, and literally millions of people using Raspberry Pis. All your questions are mostly answered.

After using this Orange Pi, I came back to one of my Raspberry Pi Zeros. Where EVERYTHING works.

And I got so happy to have this wonderful ecosystem. Where a kid goes from back-street kid to Ph.D student thanks to the Pi.

Standard