Plastic Micky – My IoT Robot to entertain the toddler

My 2 1/2 year old is robot mad.  I played him an old youtube clip of Metal Micky from the early 1980’s that was on TV when I was a kid and he has been an addict ever since.  There’s some more youtube vids of a guy in the USA retrofitting OnmniBot (again from the 80’s) with modern tech as well and he watches it over and over..

So I thought, why not build him his own one.  He’s fully into the parts and ‘how does it work’ buzz and fizzes when the AliExpress parcels turn up from China with servo’s and bits and pieces.

I wanted the thing to be a similar size to him, be able to move around, wave its arms, move its head left and right and control various LED lights and strips.  A project we can build up to do different things and tinker around with on Sunday afternoons.

Key things to sus:

  • Body – what to use? (plastic rubbish bins :))
  • Head – what to use – how to make move left and right (servo, bracket etc.)
  • Movement – Tank Tracks on the bottom for movement – Ultrasonic sensor so it can avoid stuff – like Roomba 🙂
  • Lights /Buttons to play with
  • Camera/Screen – got an old android tablet with forward facing camera to stick on the front.
  • Brain – ESP8266 Wifi Micro Controller connected to motors/servo’s/relays to control everything
  • Control – C++ Code on the ESP8266 (Arduino style) and something like Blynk for mobile phone control
  • Semi resemble Metal Micky – we call him ‘Plastic Micky’.

 

So this post is going to be the process of building it up, physically, sourcing all the bits and the electronics (as simply and cheaply as possible) to bring Micky to life..

I aim to build up the electronics using simple cheap readily available parts.. and maybe when the design is ‘stable’ – make in to a single PCB – maybe others can contribute to the design?? I’m going ‘open source’ on the electronics design and C++ code.

Here’s a link to GitHub project for the source code.. https://github.com/paulobriennz/plasticmicky

 

I’m just a beginner really with C++ and micro controllers, but I’ll have a crack.. if any one wants to make the code better – please feel free 🙂  I was even thinking, this could be a project to build in school’s for kids to learn electronics.. there’s ton’s of ‘instructable’ type articles around on the net about how to use an Arduino to make some wheels move, or lights flash, or a servo do things but not really any one stop guide that combines all the components to build a walking talking robot with mobile control and a bit of intelligence to combine movement with ‘personality’.

Also going to build an Alexa skill.. so Micky can do things by voice command as well as mobile phone control.. I’ll post the code to this as well.

 

High level, I’ve come up with an electronics design based trying a few different bits and pieces – :

  • 12v 7A Alarm Battery for Power Source (need to source a battery charging module)
  • NodeMCU/Wemos Development board – ESP8266 based – easy to ‘swap out’ and try different firmware’s etc
  • L298N Motor Controller (2A motor rating) to drive the tracks for movement (initially tried a ESP12E Motor Controller board (600ma motor rating) but not enough guts to handle robot’s weight – chip kept overheating).
  • PCA9685 16 Channel I2c Servo Control Board to move heads, arms, ears, mouth etc..
  • PCF8574 8 Channel I2c GPIO Extender – as we’re going to need a few pins to make this all happen – 6 alone for the L298N Motor Controller
  • Adjustable Buck Regulators to get 5V for Relays and electronics, LCD etc., 6-7v for Solenoids – 12v for Motors, LED Strips etc
  • OLED I2c Screen to help ‘communicate’ what’s going on.
  • Tank Tracks for movement – brought a kit with small ESP12E Motor Shield and NodeMCU – but the chip on the motor driver board is pretty gutless and just overheated trying to drive any weight on the tracks – hence the L298N controller above.  Motors connected to 12v battery directly and it was grunty as so the 12v motors and track mechanism have def got enough guts to move the thing.
  • Pan and Tilt Servo bracket for head – just using a Servo to spin the head left and right (although this area of the design needs more (mechanical) work..

 

Plan is to be able to control via Blynk (or some IoT control app) to move about and make head move, control lights etc. and have an autonomous mode (like a Roomba) that can move around and use its ultrasonic sensor (radar) to avoid objects and change course.  Also expose a ‘web service’ so we can create an Alexa skill to get it to do things.  Simple Wi-Fi Setup so you don’t have to mess round with C++ code to get it to connect – plug and play!

 

Procurement

First mission – what is the body and head going to be… after watching Metal Micky on YouTube for the 407th time with toddler, I thought – rubbish bins like you see in cafeteria’s.

I went to the Warehouse (general everything store we have in NZ – like Home Depot) and got 2 rubbish bins.

1 is a mini ‘wheelie’ bin and the other was a round bin with a push flap

 

https://www.thewarehouse.co.nz/p/living-co-wheelie-bin-black-60l/R2120555.html#start=1

https://www.thewarehouse.co.nz/p/taurus-rad-bin-50l-assorted/R638533.html#start=1

I’ll use the top off the round one for Micky’s head, and turn the wheelie bin upside down, remove the lid and casters and make a wooden base for the wheelie bin to sit on upside down.

This base can have the tracks screwed to it so its relatively ‘stable’.

 

NodeMCU Pin Map (and what ones you can actually use for stuff)

I found this picture on the internet, and it’s gold.. thank you to whoever made it – I always struggle with which pins you can actually use for stuff, and which pins will stop the thing from booting or flashing if you try and use or do weird stuff (like SD2)

For translation – Pins D10 and D9 are RX/TX for the onboard USB Serial port – so if you are using the USB Serial, you can’t use these pins

D1/D2 – normally I2c (GPIO 4,5) – tested this as well with a Servo Controller Board and I2C Scan tool

So D3 and D4 can only be used for Digital Write’s

D10 and D9 are RX/TX on the USB Serial – so if you want to debug in console, you can’t really use these easily

D1 and D2 work nice for I2c but also work for Digital Read or Write

SD3 works as GPIO10

SD2 is evidently no go – I did an I2c test on GPIO 9 (SD2) and 10 (SD3) and the I2c Scan found the device connected, but trying to use just made the NodeMCU freak and reboot

D5,D6,D7,D8 are all fully usable read and write

D0 – messes with booting up/flashing so I generally stay clear of it.

A0 is Analog Pin

Dynamics 365 – Connecting your app using MFA

MFA is becoming a common thing, as joyous as it is to use 🙂

I have a C# app that connects to Dynamics CRM/365 and I had to update it to support Microsoft Azure MFA.

I couldn’t really find any definitive guide out there, i had to cobble all different things together to get a working solution.

I hope this guide helps out some other poor sucker like me.

 

1. I had to update my application to use the modern CRM Tooling method of connection.

I added the following in Nuget to my solution – the key being the CrmTooling which supports the new connection string method of connecting.

In my code, i changed the way i obtained an IOrganizationService to the below (simplified):

string conn = "my connection string";

IOrganizationService _crmService;

CrmServiceClient service = new CrmServiceClient(conn);

_crmService = (IOrganizationService)service.OrganizationWebProxyClient != null ? (IOrganizationService)service.OrganizationWebProxyClient : (IOrganizationService)service.OrganizationServiceProxy;

 

This gets me a connection using the new Tooling DLL and a CRM Connection string.

 

Next step, you need to create an application in Azure AD.  I followed this guide.

The trick is the Redirect URI – i wasn’t working with a web app – I ended up using http://localhost

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/walkthrough-register-dynamics-365-app-azure-active-directory

 

Finally, constructing a connection string that would work with the new registered Azure App.

AuthType=OAuth;Url=https://yourcrm.crm.dynamics.com;AppId=yournewappid;RedirectUri=http://localhost;

 

Now when you go to connect, the Microsoft Sign In assistant pops up and handles the authentication to the CRM Instance.

And, if you have MFA turned on, you are also prompted with MFA.

 

Happy Days!

 

Dynamics CRM 365 – On Prem – Invalid Trace Directory

Looks like another piece of CRM team awesomeness.

The Tracing directory should be:

C:\Program Files\Microsoft Dynamics CRM\Trace

 

But some update somewhere changes it to:

c:\crmdrop\logs

 

That’s not very helpful.

I initially tried to change the trace directory back to the right place using CRM PowerShell, but that failed with authentication errors (that i have also posted on here – http://paulobrien.co.nz/2018/03/07/get-crmsetting-powershell-the-caller-was-not-authenticated-by-the-service-the-request-for-security-token-could-not-be-satisfied-because-authentication-failed/).

 

This is the guide i tried using the powershell method – makes sense, if powershell crm wasn’t broken as well.

How to fix ‘Invalid Trace Directory’ errors

 

So ended up changing in the CRM Database and registry:

 

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM]
"TraceDirectory"="C:\\Program Files\\Microsoft Dynamics CRM\\Trace"
"TraceEnabled"=dword:00000001

 

And in the MSCRM_CONFIG database:

SELECT NVarCharColumn
  FROM [MSCRM_CONFIG].[dbo].[ServerSettingsProperties]
  where ColumnName = 'TraceDirectory'

  update [MSCRM_CONFIG].[dbo].[ServerSettingsProperties]
  set NVarCharColumn = 'C:\Program Files\Microsoft Dynamics CRM\Trace'
  where ColumnName = 'TraceDirectory'

 

 

Get-CrmSetting powershell – The caller was not authenticated by the service / The request for security token could not be satisfied because authentication failed.

Had a need to run CRM powershell on an On-premise CRM Server.

I’ve had this same issue before where any powershell command you run against the Microsoft.Crm.PowerShell provider fails with authentication errors.

In this example, i was trying to run this and it barfed on Get-CrmSetting ….

Add-PSSnapin Microsoft.Crm.PowerShell

$ClaimsSettings = Get-CrmSetting -SettingType OAuthClaimsSettings

$ClaimsSettings.Enabled = $true

Set-CrmSetting -Setting $ClaimsSettings

 

Turned out to fix it, i needed to add a registry key.  After i did this it worked straight away (no need to reboot or reopen the PS window).

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"DisableLoopbackCheck"=dword:00000001

 

Method 2 in this article:

https://support.microsoft.com/en-us/help/896861/you-receive-error-401-1-when-you-browse-a-web-site-that-uses-integrate