Arduino Pinmode procedure not working

Published by Noah0705 on
Status
Fixed
Issue description

If I use the code template "Set mode of pin (Pin Number) to (Pin Mode)" it doesn't work (replicating the tutorial)

 

I need to type /link pinmode 13 output for it to work (same thing for input and input_pullup)
program is from "Setting default pin modeshttps://mcreator.net/wiki/minecraft-link-mcreator-procedures

package net.mcreator.mcduino.procedures;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.common.MinecraftForge;

import net.mcreator.minecraft.link.event.LinkDeviceConnectedEvent;
import net.mcreator.minecraft.link.devices.PinMode;
import net.mcreator.minecraft.link.CurrentDevice;
import net.mcreator.mcduino.MCDuinoElements;

@MCDuinoElements.ModElement.Tag
public class DefaultPinModeProcedure extends MCDuinoElements.ModElement {
	public DefaultPinModeProcedure(MCDuinoElements instance) {
		super(instance, 3);
		MinecraftForge.EVENT_BUS.register(this);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		CurrentDevice.pinMode((int) 13, PinMode.OUT);
		CurrentDevice.pinMode((int) 6, PinMode.IN_P);
		CurrentDevice.pinMode((int) 5, PinMode.IN_P);
		CurrentDevice.pinMode((int) 4, PinMode.IN_P);
		CurrentDevice.pinMode((int) 3, PinMode.IN_P);
	}

	@SubscribeEvent
	public void onLinkDeviceConnected(LinkDeviceConnectedEvent event) {
		this.executeProcedure(new java.util.HashMap<>());
	}
}

 

and the block that outputs to the led (arduino builtin led)

package net.mcreator.mcduino.procedures;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;

import net.mcreator.minecraft.link.CurrentDevice;
import net.mcreator.mcduino.MCDuinoElements;

@MCDuinoElements.ModElement.Tag
public class NightDetectorUpdateTickProcedure extends MCDuinoElements.ModElement {
	public NightDetectorUpdateTickProcedure(MCDuinoElements instance) {
		super(instance, 4);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure NightDetectorUpdateTick!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure NightDetectorUpdateTick!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure NightDetectorUpdateTick!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure NightDetectorUpdateTick!");
			return;
		}
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		CurrentDevice.digitalWrite((int) 13,
				(((world.isDaytime()) && (world.canBlockSeeSky(new BlockPos((int) x, (int) y, (int) z))))) ? (byte) 1 : (byte) 0);
	}
}

 

Issue comments

i followed the tutorial from the link above (this one https://mcreator.net/wiki/minecraft-link-mcreator-procedures).

i made a "procedure" called DefaultPinmode that runs when a new device is connected (MCreator Link: New device connected)

and sets the pins.
  .

and for some reason it doesnt execute.

if I didn't answer the question or properly its because i have difficulty reading/writing in english.
 

Could you add another print block here and check in the console if "device connected" event gets triggered?

I don't know because I don't know why this is happening. If command works, you might be able to use execute command procedure block to run /link pinmode command from there.

I see, because there is no world reference in device connected procedure. I am afraid there is no workaround for this, I will check why it is not working.

With run command block, but unfortunately, this block requires world dependency that is not provided by the device connected event.

Could you do one more test?

Use your original procedure with pinmode blocks and trigger it on when player joins the world.

Connect to the Arduino before opening the world and then join the world. Please report back if this works.

Yes, try if this work.

I think I found the actual cause for this problem in MCreator link too.

Ok but this is a workaround, I will leave this open until there is a proper fix. Should be today as I am working on it right now.

There is a time limit on how often data can be sent to Arduino in milliseconds to prevent flooding and freezing it and this time limit prevents sending data immediately after connect and this is when you try to send pinmode data.

I am surprised no one noticed this so far.

You can check the source here: https://github.com/Pylo/MCreatorLink It is opensource :)

also what would happen if you connect an Raspberry pi and an arduino at the same time? (if it's even possible)

and is there a way to connect them to a server? (the normal connect option only gives -1)

You can run this on server, but need to run procedures on server only then and connect to the devices via server commands.

i was hoping it connected via the client (was thinking of making some very interesing features (opening doors, activate lighting, enable redstone system etc. etc.)

I don't think you understood me. You can connect from client-side too.

If you use dedicated server, it is logical server is the one connecting to the device, not separate clients.

If you use client game, client connects to the Arduino.

The bug was fixed. You need to update link library. To do this, click on link icon next to "N mod elements" text in workspace and click Update MCreator Link library.

In next build or launch, the bug should be gone.